Hi
is it possible to override system date in SAS Program. I have a batch job that I need to re-run.
I need to ensure that system date is read as 1st April 2017 and not actual today's date.
Well, technically it possible to get your IT to change the system clock. I would however find that to be a major breach of the infrastructure. The current date time is there for a reason, if you want to put a specific date in a document or something then put that in, but don't refer to it as "system date" then.
Is your program using any variable to hold the date of interest? It may be that you need to modify the program as "one time" job to have the date literal for the day of interest in place of whatever may be looking at system dates or date functions such as today().
Or show the code that uses a date value to see what suggestions may be available.
DO.NOT.DO.THAT.
The IT people will have your hide hanging over their door, as a reminder for others. And do so for a reason. Actually not one reason, but many.
If you need to re-run a batch job, it should correctly record today's date as the date of the rerun. Job specific date values (eg the month for which an accounting job runs) should NEVER be taken from the system date, but be supplied to the job from the scheduler.
Our end-of-month batch jobs run over the course of several days, but all have the same "execution date". Rerunning them correctly is as easy as editing a script file and running that. And the logs will fatefully capture that a certain job was rerun for a certain execution date on a later day; this way we hold everything accountable, as mandated by law(!).
Hi,
I also have the same requirement as you.
I also confirmed with SAS Support (Thailand) that there is no way to override a system date.
The best way is to declare macro variable to handle the execution date.
Here is example.
Before
t1.SALES_DATE >= INPUT(PUT(Intnx('Month', TODAY()-1 ,- 0, 'B'), YYMMDDN8.), 8.)
After
%let _Current_Date_= 01MAY2023;/*for normal case : set value=%sysfunc(today(), date9.); , for rerun: set value as a specific date*/
%put Current_Date=&_Current_Date_.;
t1.SALES_DATE BETWEEN INPUT(PUT(Intnx('Month', "&_Current_Date_."d -1 ,- 0, 'B'), YYMMDDN8.), 8.)
AND INPUT(PUT(Intnx('Month', "&_Current_Date_."d -1 ,- 0, 'E'), YYMMDDN8.), 8.)
Construct you program so that it only uses the current date when a date is not supplied.
Say your program needs to subset the data to specific range of days. You might use a pair of macro variables (or environment variables or data set variables etc) named STARTDT and ENDDT.
Just have the program test if the value has been supplied and if not then use the default.
%if 0=%length(&startdt) %then %do;
%let startdt="%sysfunc(intnx(month,%sysfunc(today()),0,b),date9.)"d ;
%end;
%if 0=%length(&enddt) %then %do;
%let enddt="%sysfunc(intnx(month,%sysfunc(today()),0,e),date9.)"d ;
%end;
If you use environment variables you can use the -SET command line option to set the value on the command that runs the SAS program.
An even better solution is to set up your SAS program so it either defaults to the system date, or reads in a job run date as an environment variable (see the SAS SYSGET function for details of how to do this). That way no code change is required to run your program for a different date, just specify it in the environment variable.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.