I have a list of directories in the form of work.Directories.data, let's say (variable is directory). Each row contains a string that looks like this:
C:\importantfolder\subfolder\
I want to find the contents of each of these directories and combine them to make a new dataset. Here is what I have so far:
%macro ScanDirec(STRING=);
filename temptree pipe 'dir "&STRING" /s /b' lrecl=5000;
data SmallList;
infile temptree truncover;
input dirlist $char1000.;
run;
data BigList;
set BigList SmallList;
run;
%mend ScanDirec;
data SmallList;
run;
data BigList;
run;
data _null_;
set Directories;
call execute('%ScanDirectories('||directory||')');
run;
I get some serious problems, but I think my code looks pretty harmless. What is the issue?
The error message seems pretty straight forward.
1 data test ;
2 infile 'dir "&STRING" /s /b' pipe truncover;
3 input dirlist $char1000.;
4 run;
NOTE: The infile 'dir "&STRING" /s /b' is:
Unnamed Pipe Access Device,
PROCESS=dir "&STRING" /s /b,RECFM=V,
LRECL=32767
Stderr output:
File Not Found
NOTE: 0 records were read from the infile 'dir "&STRING" /s /b'.
NOTE: The data set WORK.TEST has 0 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.99 seconds
cpu time 0.04 seconds
Windows could not find any files named "&STRING"
.
Use double quotes around your strings if you want SAS to resolve your macro expressions.
"dir ""$STRING"" /s /b"
Or just avoid macro completely.
data BigList;
set Directories;
length cmd $500 ;
cmd = catx(' ','dir',quote(trim(directory)),'/s /b');
infile cmd pipe filevar=cmd truncover end=eof;
do while (not eof);
input dirlist $char1000.;
output;
end;
run;