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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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