LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (July 2007, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Sun, 22 Jul 2007 11:20:20 -0700
Reply-To:     RolandRB <rolandberry@HOTMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         RolandRB <rolandberry@HOTMAIL.COM>
Organization: http://groups.google.com
Subject:      Re: function style macros
Comments: To: sas-l@uga.edu
In-Reply-To:  <1185127787.051933.321370@g4g2000hsf.googlegroups.com>
Content-Type: text/plain; charset="us-ascii"

On 22 Jul, 20:09, RolandRB <rolandbe...@hotmail.com> wrote: > On 21 Jul, 15:29, RolandRB <rolandbe...@hotmail.com> wrote: > > > > > > > On 21 Jul, 14:49, RolandRB <rolandbe...@hotmail.com> wrote: > > > > On 20 Jul, 23:58, cmill...@COQIO.SDPS.ORG (Cary Miller) wrote: > > > > > I want to get the size of system files. If I had the good fortune > > > > to be working on Unix it would be no problem with FINFO. Unhappily > > > > I am stuck with windows and have to go to lengths to get this simple > > > > piece of information. Here is how I have done it. > > > > > %macro fileSize(fname); > > > > %global size; > > > > data files; > > > > length line $99.; > > > > filename foo PIPE "dir &fname"; > > > > infile foo; > > > > input line $1-99; > > > > if _n_ EQ 3; > > > > size = scan(line, 4, ' '); > > > > call symput('size', size); > > > > run; > > > > %mend; > > > > > %filesize(s:\~Cary\start.html); > > > > %LET fs= &size; > > > > > This code works but is unsatisfying. Instead I would like to say > > > > > %let fs = %filesize(s:\~Cary\start.html); > > > > > but I cannot because a data step inside a macro undergoes > > > > text substitution and a data step cannot go to the right of > > > > an equal sign. %sysfunc almost works but 'input' is one of > > > > the functions that is not allowed as an argument to %sysfunc. > > > > So I need > > > > 1. to make a data step in a macro not undergo text substitution. > > > > 2. to not use 'input' in the data step. > > > > 3. some other way to get file information. > > > > > Any suggestions? > > > > See my %readpipe() macro. You should be able to amend it to write the > > > function-style macro you are trying to write.http://www.datasavantconsulting.com/roland/spectre/macros/readpipe.sa...quoted text - > > > > - Show quoted text - > > > Try this: > > > %macro dosfilesize(dosfile); > > %local fname fid str rc rec; > > %let rc=%sysfunc(filename(fname,dir &dosfile,pipe)); > > %if &rc NE 0 %then %do; > > %put ERROR: (dosfilesize) Pipe file could not be assigned due to the > > following:; > > %put %sysfunc(sysmsg()); > > %end; > > %else %do; > > %let fid=%sysfunc(fopen(&fname,s)); > > %if &fid EQ 0 %then %do; > > %put ERROR: (dosfilesize) Pipe file could not be opened due to the > > following:; > > %put %sysfunc(sysmsg()); > > %end; > > %else %do; > > %let rec=0; > > %do %while(%sysfunc(fread(&fid)) EQ 0); > > %let rc=%sysfunc(fget(&fid,str,200)); > > %let rec=%eval(&rec+1); > > %if &rec EQ 6 %then %do; > > %qscan(%quote(&str),3,%str( )) > > %end; > > %end; > > %let rc=%sysfunc(fclose(&fid)); > > %if &rc NE 0 %then %do; > > %put ERROR: (dosfilesize) Pipe file could not be closed due to the > > following:; > > %put %sysfunc(sysmsg()); > > %end; > > %let rc=%sysfunc(filename(fname)); > > %if &rc NE 0 %then %do; > > %put ERROR: (dosfilesize) Pipe file could not be deassigned due to the > > following:; > > %put %sysfunc(sysmsg()); > > %end; > > %end; > > %end; > > %mend; > > This should work and does (it uses my %readpipe() macro) but it gives > out a double error message and the best I can do is to get it down to > one error message. Can anyone help out with the magic macro quoting > techniques? > > %macro dosfilesize(dosfile); > %readpipe(for %A in (&dosfile) do @echo %~zA) > %mend; > > 32 %put >>>> %dosfilesize(C:\spectre\unistats.html); > WARNING: Apparent invocation of macro A not resolved. > WARNING: Apparent invocation of macro A not resolved. > > > > >>>> 180470- Hide quoted text - > > - Show quoted text -- Hide quoted text - > > - Show quoted text -

This works.

%macro dosfilesize(dosfile); %local A; %let A=%nrstr(%A); %readpipe(for &A in (&dosfile) do @echo %~zA) %mend;


Back to: Top of message | Previous page | Main SAS-L page