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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 4 replies
  • 882 views
  • 0 likes
  • 3 in conversation