dataset - SAS, handle Macro output -
i took sas macro sas website, in order list file in folder. thit full reference: http://support.sas.com/kb/25/074.html .
and that's code:
%macro drive(dir,ext); %let filrf=mydir; /* assigns fileref of mydir directory , opens directory */ %let rc=%sysfunc(filename(filrf,&dir)); %let did=%sysfunc(dopen(&filrf)); /* returns number of members in directory */ %let memcnt=%sysfunc(dnum(&did)); /* loops through entire directory */ %do = 1 %to &memcnt; /* returns extension each file */ %let name=%qscan(%qsysfunc(dread(&did,&i)),-1,.); /* checks see if file contains extension */ %if %qupcase(%qsysfunc(dread(&did,&i))) ne %qupcase(&name) %then %do; /* checks see if extension matches parameter value */ /* if condition true prints full name log */ %if (%superq(ext) ne , %qupcase(&name) = %qupcase(&ext)) or (%superq(ext) = , %superq(name) ne) %then %do; %put %qsysfunc(dread(&did,&i)); %end; %end; %end; /* closes directory */ %let rc=%sysfunc(dclose(&did)); %mend drive; /* first parameter directory of files stored. */ /* second parameter extension looking for. */ /* leave 2nd paramater blank if want list of files. */ %drive(c:\,sas)
this macro (obviously) works fine, problem returns results on log. need put results sas dataset in order schedule other operations. how can it?
thanks in advance.
first off, if can make pipe, can do:
filename dirlist pipe "dir /b c:\*.sas"; data myfiles; infile dirlist lrecl=512 truncover; input @1 fullname $512.; filename = scan(fullname,-1,'\'); run;
if need use macro due system restrictions, can't take output directly doesn't other print log. you'll need 1 of 2 things:
- use proc printto redirect log file, can parse
change line of code something.
%put %qsysfunc(dread(&did,&i));
if change to, say,filename = dread(&did,&i); output;
then call macro inside data step , can use results. realistically might better off running of in datastep , not bothering macro - it's more complicated needs in order macro-only; in datastep that's shorter.
Comments
Post a Comment