BookmarkSubscribeRSS Feed
Mahesh_K
Calcite | Level 5
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!
4 REPLIES 4
Patrick
Opal | Level 21
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)?
Mahesh_K
Calcite | Level 5
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.
FredrikE
Rhodochrosite | Level 12
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

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1751 views
  • 0 likes
  • 3 in conversation