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

Hi, I am new SAS user. I am using SAS online demand version. I would like list all files from folder/subfolder. I tried below code but am neither am getting output nor error. Could you please help me

data yfiles;
 keep filename;
 length fref $8 filename $80;
 rc = filename(fref, 'path of folder/subfolder');
 if rc = 0 then
 do;
 did = dopen(fref);
 rc = filename(fref);
 end;
 else
 do;
 length msg $200.;
 msg = sysmsg();
 put msg=;
 did = .;
 end;
 if did <= 0
 then
 putlog 'ERR' 'OR: Unable to open directory.';
 dnum = dnum(did);
 do i = 1 to dnum;
 filename = dread(did, i);
 /* If this entry is a file, then output. */
 fid = mopen(did, filename);
 if fid > 0
 then
 output;
 end;
 rc = dclose(did);
 run;
 proc print data=yfiles;
 run;
1 ACCEPTED SOLUTION

Accepted Solutions
SASCODERS
Fluorite | Level 6

At the end of path I didn't give the "/" previously. That's why i didn't get the output. Now am getting output. Thank you.

View solution in original post

2 REPLIES 2
japelin
Rhodochrosite | Level 12

I tried your code in SAS OnDemand for Academics and it outputs a file list.

japelin_0-1649063766665.png

 


Are you specifying the directory path correctly?

 

  rc = filename(fref, '/home/myusername/');/* specify "path of folder/subfolder" */

 

It is strange that you get no results at all, so please paste the log after submitting.

 

 

SASCODERS
Fluorite | Level 6

At the end of path I didn't give the "/" previously. That's why i didn't get the output. Now am getting output. Thank you.

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
  • 2 replies
  • 473 views
  • 1 like
  • 2 in conversation