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;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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