Hi there
I have a batch job that I need to re-run which uses the Today() function throughout the code. I appreciate that I can go and change these references and also for future use adapt the program so the Today() is used once at the start of the program to create a macro variable that is referenced in the rest of the code.
However, is it also possible to force the Today() to be a specific date value within a SAS session instead of defaulting to todays date?
Thank you
If you want a specific date then you wouldn't use the TODAY function at all.
A good approach is to assign the program run date to a macro variable like so:
*%let Run_Date = 18May2021;
%let Run_Date = %sysfunc(today(), date9.);
Then use the macro variable throughout your code. If you want a specific date then uncomment the specific date assignment and comment the TODAY statement.
If you are running a batch job then you can pass in the required date in as a job parameter and avoid any coding changes. How you do that would depend on how you are scheduling the job.
@Rachie wrote:
However, is it also possible to force the Today() to be a specific date value within a SAS session instead of defaulting to todays date?
Is this what you want?
%let today = %sysevalf('01MAY2021'd);
Hello @Rachie
As you are running a batch process you can pass a date as a parameter if you want to use a date other today. . For example
Yourpath_to_sas/SAS.EXE -SYSPARM "01JAN2012"
Now in the code you can have something like this
%if &sysparam=' ' %then %do;
%let Run_Date = %sysfunc(today(), date9.);
%end;
%else %do
%let Run_Date = "&sysparam"d;
%end;
Something like this:
%let override_date = %sysfunc(mdy(1, 1, 2021));
%let today = %sysfunc(coalescec(&override_date., %sysfunc(today())));
%put &today;
%let override_date =;
%let today = %sysfunc(coalescec(&override_date., %sysfunc(today())));
%put &today;
@Rachie wrote:
Hi there
I have a batch job that I need to re-run which uses the Today() function throughout the code. I appreciate that I can go and change these references and also for future use adapt the program so the Today() is used once at the start of the program to create a macro variable that is referenced in the rest of the code.
However, is it also possible to force the Today() to be a specific date value within a SAS session instead of defaulting to todays date?
Thank you
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.