Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Auto run SAS programs against the latest version of a dataset?

Status
Not open for further replies.

jamesk1979

IS-IT--Management
May 22, 2003
15
AU
Hi all,

I'm a bit a SAS novice so apologies if this sounds a bit dumb.

I get a backup of a system file each day, with the date tagged on to the end of the dataset name in the format YYMMDD.

At the moment I am changing my SAS programs each day to look at the latest version, e.g. today I changed it from 060108 to 060109.

Is there a way for me to always have the program look at the latest version of the file available? So the program runs against the dataset in today's YYMMDD format, if that doesn't exist it runs against YYMMDD(-1) etc.?

My code usually follows this format;

%let master = lib.file060108;

proc sql;
*get the variables
from &master

etc

Many thanks,
James.
 
JamesK1979,
There are many ways to have you program look for the correct dataset, so that you don't have to modify your SAS code each day. The simplest way would be to have your code use the dataset with today's name. You could have a macro var that self populates itself like this:
Code:
%let DateToday = %sysfunc(putn(%sysfunc(date()),yymmdd6.));

This code will generate a macro value of the current date in a macro var named DateToday.
In short, what you need to design is a SAS program that will call your current program through the use of '%inc' macro language.

This is just the start of the wonderful world of include file programming. You mentioned that you may want to check the current date - 1 day for latest data file. While this may work if the data file was updated the day before it will fail when the data hasn't been updated for a while. What I suggest is write a short sas program that will give a full list of SAS data files at your source storage place (a folder). Then use the proc sort to sort them and take the last one.

If you need any further help feel free to ask.
Klaz
 
As an alternative, if you have a data _null_ step to set up some of your macro variables already, you can use this form instead:-
Code:
data _null_;
  call symput('DATETODAY',put(today(),yymmdd6.));
run;

Klaz's suggestion of getting a list of files and checking the most recent is a good idea, it allows greater automation of the process, just be sure to include exception reporting for when things go wrong (empty files, no file found, same file as previously loaded etc).
 
Thanks klaz and Chris, I'll give these a try...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top