DATA Step, Macro, Functions and more

Automation Help - Parsing the most recent file in a folder

Reply
New Contributor
Posts: 2

Automation Help - Parsing the most recent file in a folder

I would be grateful if someone could help automate the task of a weekly job that I need to run every Monday.

There are about 10 different files that an existing piece of code reads. All of these files are in a folder say D:\SASFILES.

The issue is the file is dumped into this folder and the folder also has all historical dumps of the file. The latest file is identified by the latest time stamp.

Below is an example of one of the files "MEM122-ALI-FamilySnapShotExtract". The folder contains these files:

MEM122-ALI-FamilySnapShotExtract_2009-02-16-07-34-32.txt
MEM122-ALI-FamilySnapShotExtract_2009-02-23-05-35-26.txt
MEM122-ALI-FamilySnapShotExtract_2009-03-02-05-29-14.txt

The latest file is MEM122-ALI-FamilySnapShotExtract_2009-03-02-05-29-14.txt i.e. that was created on 2nd March 2009.

I want to be able to set a variable say D121SA to point to this file

e.g.

%LET D121SA = MEM122-ALI-FamilySnapShotExtract_2009-03-02-05-29-14.txt ;

Any help appreciated!
Respected Advisor
Posts: 3,901

Re: Automation Help - Parsing the most recent file in a folder

Do you know what datepart the timestamp part of the filename you want to read has when you run the code - or is this something you would have to determine as well (i.e. by reading the file with the most current date)?
New Contributor
Posts: 2

Re: Automation Help - Parsing the most recent file in a folder

The timestamp is included in the file name

e.g. _2009-02-16-07-34-32.txt

Alternatively, it could also be the latest file in the directory.
Respected Advisor
Posts: 3,901

Re: Automation Help - Parsing the most recent file in a folder

Thanks Proccontents.
I was just going to write an answer before I read your post.

http://groups.google.com.au/group/comp.soft-sys.sas/browse_thread/thread/382ea2336c72e44/190b2aef220...
Frequent Contributor
Posts: 120

Re: Automation Help - Parsing the most recent file in a folder

Something like this might be a start:

filename test pipe 'dir /OD';

data _null_;
infile test;
length a $2000;
input a;
if _n_ = 1 then put a=;
run;

//Fredrik
Ask a Question
Discussion stats
  • 4 replies
  • 156 views
  • 0 likes
  • 3 in conversation