BookmarkSubscribeRSS Feed
Rachie
Calcite | Level 5

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

 

5 REPLIES 5
SASKiwi
PROC Star

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.

PaigeMiller
Diamond | Level 26

@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);
--
Paige Miller
Sajid01
Meteorite | Level 14

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;
Reeza
Super User

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

 


 

sas-innovate-white.png

Register Today!

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.

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1664 views
  • 3 likes
  • 6 in conversation