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

can someone please explain to me the code below and how i can make modification to it to still run, basically i am trying to edit the code to be more simple and understantable

 

here is the code

 

 data dirlist;
 rc=filename ("fdir","&path");
 did=dopen("fdir");
 if did>0 then do;
 num=dnum(did);
 do i = 1 to num;
 fname=dread(did,i);
 output;
 end;
 end;
 run;

 

thank you

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

This is using SAS functions to read the names of external files. Using this approach there isn't anything that will get simpler.

Basically

data dirlist;
    rc=filename ("fdir","&path");  /*Assign a reference SAS can use to a folder or directory*/
    did=dopen("fdir");   /* attempt to open the directory for reading*/
    if did>0 then do;    /* if successful opening */
       num=dnum(did);    /* get the number of files in the directory*/
       do i = 1 to num;
          fname=dread(did,i);  /* retrieve the file names*/
          output;
       end;
    end;
 run;

There are operating system options involving pipes and such to get the output of system commands with file lists and read them but they are operating system dependent.

 

View solution in original post

1 REPLY 1
ballardw
Super User

This is using SAS functions to read the names of external files. Using this approach there isn't anything that will get simpler.

Basically

data dirlist;
    rc=filename ("fdir","&path");  /*Assign a reference SAS can use to a folder or directory*/
    did=dopen("fdir");   /* attempt to open the directory for reading*/
    if did>0 then do;    /* if successful opening */
       num=dnum(did);    /* get the number of files in the directory*/
       do i = 1 to num;
          fname=dread(did,i);  /* retrieve the file names*/
          output;
       end;
    end;
 run;

There are operating system options involving pipes and such to get the output of system commands with file lists and read them but they are operating system dependent.

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 1 reply
  • 1083 views
  • 0 likes
  • 2 in conversation