BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
AshokD
Obsidian | Level 7

Hi,

 

I am using date functions like today(), intnx etc. in my code.

Is there any way to point SAS date to yesterday at starting of the session ?

 

Example:-

 

data _null_;
call symput('run_dt', put(today(),yymmddn8.));  -->As per exisiting logic, this will return today's date.
run;

 

Is there any way to define SAS date prior to the above step, so by default it will point to yesterday's date ?

Note - I don't want to use today()-1 

Please share your thoughts.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

@AshokD wrote:

Hi,

 

My code has about 2k+ lines , they have used today() functions in so many places in the code. For some reason I need to run the job to pull data as of yesterday. Instead of changing the code today()-1 in all the places, is there any way to define current date as yesterday at the starting of the code so that today() function resolves to yesterday in all the logics placed in the code.

 

Is there any possibility ?


No, unless you reset the SAS server's system clock.

 

Do a search and replace in your code, and replace every occurence of today() with

&todays_date.

At the beginning of your code, insert

%let todays_date=%eval(%sysfunc(today()) - 1);

Now you only need to change this line in the future.

View solution in original post

5 REPLIES 5
Astounding
PROC Star
You already know the best way ... today()-1. If you want a more complex way to help preserve job security, you can use:

intnx("day", today(), -1)
ed_sas_member
Meteorite | Level 14

Hi @AshokD 

Would you like to identify the day before today or the day before the opening of the SAS session?

It can be quite different. In the last case, it would be better to use &sysdate rather than today().

Best,

AshokD
Obsidian | Level 7

Hi,

 

My code has about 2k+ lines , they have used today() functions in so many places in the code. For some reason I need to run the job to pull data as of yesterday. Instead of changing the code today()-1 in all the places, is there any way to define current date as yesterday at the starting of the code so that today() function resolves to yesterday in all the logics placed in the code.

 

Is there any possibility ?

jklaverstijn
Rhodochrosite | Level 12

In short: no.

The longer answer: today() is what it is: today.

Regards,

Jan.

Kurt_Bremser
Super User

@AshokD wrote:

Hi,

 

My code has about 2k+ lines , they have used today() functions in so many places in the code. For some reason I need to run the job to pull data as of yesterday. Instead of changing the code today()-1 in all the places, is there any way to define current date as yesterday at the starting of the code so that today() function resolves to yesterday in all the logics placed in the code.

 

Is there any possibility ?


No, unless you reset the SAS server's system clock.

 

Do a search and replace in your code, and replace every occurence of today() with

&todays_date.

At the beginning of your code, insert

%let todays_date=%eval(%sysfunc(today()) - 1);

Now you only need to change this line in the future.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 857 views
  • 0 likes
  • 5 in conversation