BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
hellohere
Pyrite | Level 9

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 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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;

View solution in original post

3 REPLIES 3
Kurt_Bremser
Super User
%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;

hellohere
Pyrite | Level 9

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

Kurt_Bremser
Super User

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;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1759 views
  • 1 like
  • 2 in conversation