Suppose you have a set of data files that you need to read into SAS, but there is no systematic pattern to the names. Here I describe two ways to do this. The second is some text I put together as bits and pieces. The first is a more elegant solution I found somewhere, but have yet to try.
rc=filename('mydir','.');
dirid=dopen('mydir');
do i=1 to dnum(dirid);
...SAS statements...
end;
rc=dclose(dirid);
FILENAME fileref 'filenames.txt'; /* 'fileref' must be 8
chars or less */
data filenames;
length var1 $200;
infile fileref;
input var1;
run;
data _null_;
set filenames nobs=nobs;
call symput('out'||left(_n_), var1);
run;
%macro doit;
%do i=1 %to 248; /* 248 needs to be the number of filenames
from filenames.txt that you want to read in */
%let docname=&&out&i;
filename mydata pipe cat &docname | tr -d
'\r' ;
data subfile;
infile mydata lrecl=500 truncover dsd;
informat x y;
input x y;
run ;
proc append base=full data=subfile2 force;
run;
%PUT &docname;
%end; %mend doit;
%doit; run;