I found the code below (originally without any of the macro code) that inventories directories and it's lightning quick. I want to turn it into a macro so I can call it when I need it, but when I put the &path in place of the literal path it resolves as &path rather than inserting the path I called in the macro. I tried switching the single and double quotes and it looks like &path resolves to the correct path but now the coding doesn't work (Stderr output: The specified path is invalid.). It works perfectly when I just paste the path into the code. What can I do to turn this into a macro?
Thanks.
%macro get_file_info(path); /* http://support.sas.com/resources/papers/proceedings12/058-2012.pdf */ filename pipedir pipe ' dir "I:\VRBIS\TransaxAchieve-UCD" /S' lrecl=5000; /* filename pipedir pipe ' dir "&path" /S' lrecl=5000;*/ data indata; infile pipedir truncover; input line $char1000.; length directory $1000; retain directory; if line =' ' or index(upcase(line),'<DIR>') or left(upcase(line))=:'VOLUME' then delete; if left(upcase(line))=:'DIRECTORY OF' then directory=left(substr(line,index(upcase(line),'DIRECTORY OF')+12)); if left(upcase(line))=:'DIRECTORY OF' then delete; if input(substr(line,1,10),?? mmddyy10.) = . then substr(line,1,10)='12/31/2999'; date=input(substr(line,1,10),?? mmddyy10.); format date mmddyy10.; run;
proc sort data=indata; by directory descending date; run;
data Directory_Summary(drop=i line); set indata; by directory; length filename $75; retain number_of_files_in_directory directory_size; if first.directory then do; number_of_files_in_directory=input(scan(line,2,' '),32.); directory_size=input(scan(line,4,' '),comma32.); end; file_size=input(scan(line,4,' '),comma32.); filename=' '; do i=5 to 100; filename=trim(left(filename))||' '||scan(line,i,' '); if scan(line,i,' ')=' ' then leave; end; if index(upcase(line),'FILE(S)') then delete; if date ge '30DEC2999'd then delete; run; %mend get_file_info;
/*%include 'H:\SAS code\Directory_summary.sas';*/ %get_file_info(I:\VRBIS\TransaxAchieve-UCD);
... View more