Your SAS programs, embedded in web apps and elsewhere

Directory Scans

Reply
N/A
Posts: 0

Directory Scans

Is there a way SAS can scan a directory for a filename?

I'm trying to automate a monthly reporting process. One of the files I need to use is only updated quarterly. They are kind enough to put the year and month in the file name (0512) and leave the rest of the file name identical. What I would like to do is scan the directory for the files aa0509bb.dbf aa0512bb.dbf and automatically determine which is the most recent and use that in my proc sql to link to other datasets.

Thanks.
SAS Super FREQ
Posts: 304

Re: Directory Scans

Posted in reply to deleted_user
Bob-

This forum is intended for the discussion of issues pertaining to SAS Stored Processes:

http://support.sas.com/rnd/itech/doc9/dev_guide/stprocess/index.html

I believe the External File class of the SAS/AF product, or other functions of SAS/AF, provide a fairly straightforward way of getting a list of files in a directory.

In the DATA Step, most people use a pipe+host directory command to get a list of files.

Either way, once you get a list of files, you can put them into a SAS table and sort them, and/or use regular expressions or other character functions to manipulate the file names as you see fit.

I hope that this helps you along the way.

Best regards,

Vince DelGobbo
SAS R&D
N/A
Posts: 0

Re: Directory Scans

Posted in reply to Vince_SAS
Vince@SAS: If you don't give people a forum to discuss the pertinent issue above, you will get people posting off topic.

So put a forum topic in place to capture these demands, and you will get pure topic postings.
SAS Employee
Posts: 1

Re: Directory Scans

Posted in reply to deleted_user
Hi Bob,
There are some useful file functions which you can use within a datastep. The following example reads only XLS files from a certain place. Cheers Peter

DATA save.input_files (KEEP = filename filepath id);
LENGTH filename filepath $256;
rc=FILENAME("readdir","&filepath");
did=DOPEN("readdir");
memcount=DNUM(did);
DO i = 1 TO memcount;
filename = DREAD(did,i);
IF UPCASE(scan(filename,-1,".")) = "XLS" THEN
DO;
filepath = "&filepath\" !! TRIM(LEFT(filename));
id = i;
output;
END;
END;
rc=DCLOSE(did);
RUN;
Ask a Question
Discussion stats
  • 3 replies
  • 277 views
  • 0 likes
  • 3 in conversation