I have a directory which has 1000+ .csv files to read-in. The filenames are changing.
How to get the filename list so that can read-in one by one?! Thanks
Which means that either the path is not available in your SAS session, or is empty. Expand the code to see which of that is true:
data names;
length fref $8 name $200;
rc = filename(fref,"&path.");
did = dopen(fref);
if did
then do;
do i = 1 to dnum(did);
name = dread(did,i);
output;
end;
rc = dclose(did);
end;
else put "Directory not found!";
rc = filename(fref);
keep name;
run;
%let path=...;
data names;
length fref $8 name $200;
rc = filename(fref,"&path.");
did = dopen(fref);
if did
then do;
do i = 1 to dnum(did);
name = dread(did,i);
output;
end;
rc = dclose(did);
end;
rc = filename(fref);
keep name;
run;
Great. But how to use it?!
I tried and get null
14653 %let path=E:\outsas\; 14654 14655 data names; 14656 length fref $8 name $200; 14657 rc = filename(fref,"&path."); 14658 did = dopen(fref); 14659 if did 14660 then do; 14661 do i = 1 to dnum(did); 14662 name = dread(did,i); 14663 output; 14664 end; 14665 rc = dclose(did); 14666 end; 14667 rc = filename(fref); 14668 keep name; 14669 run; NOTE: The data set WORK.NAMES has 0 observations and 1 variables. NOTE: DATA statement used (Total process time): real time 0.01 seconds cpu time 0.01 seconds
Which means that either the path is not available in your SAS session, or is empty. Expand the code to see which of that is true:
data names;
length fref $8 name $200;
rc = filename(fref,"&path.");
did = dopen(fref);
if did
then do;
do i = 1 to dnum(did);
name = dread(did,i);
output;
end;
rc = dclose(did);
end;
else put "Directory not found!";
rc = filename(fref);
keep name;
run;
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.