BookmarkSubscribeRSS Feed
gskn4u
Obsidian | Level 7

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. 

6 REPLIES 6
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.  

ballardw
Super User

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.

Kurt_Bremser
Super User

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(!).

kun_ming
Calcite | Level 5

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.)

Tom
Super User Tom
Super User

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.

SASKiwi
PROC Star

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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 6 replies
  • 1898 views
  • 0 likes
  • 7 in conversation