C:\ab\cd\filename DIRLIST pipe 'dir "C:\ab\cd\*.txt" /b ';
data dirlist ;
infile dirlist lrecl=200 truncover;
input file_name $100.;
run;
****Part I; old file;
data _null_;
set dirlist end=end;
count+1;
call symputx('read'||put(count,4.-l),cats('C:\ab\cd\',file_name));
call symputx('dset'||put(count,4.-l),scan(file_name,1,'.'));
if end then call symputx('max',count);
run;
options mprint symbolgen;
%macro readin;
%do i=1 %to &max;
data &&dset&i;
infile "&&read&i" lrecl=1000 truncover dsd;
input var1 $ var2 $ var3 $;
run;
%end;
%mend readin;
%readin;
The limitation is that it can show limited amount of variables. If I am not sure how many variables they have, I want to use another loop.
options mprint symbolgen; ******part II, new one; I want to replace the part I with code below by adding &j so that I need not know how many variables each file has, need not type var1, var2, var3, etc;
%macro readin;
%do i=1 %to &max;
%do j=1 %to &max;
data &&dset&i;
infile "&&read&i" lrecl=1000 truncover dsd;
input var&j $
run;
%end;
%end;
%mend readin;
%readin;
... View more