BookmarkSubscribeRSS Feed
Rajeshganta
Calcite | Level 5
I want to change the date in sysdate for some automation like
%let sysdate = today()-4;
This is not working please help me solve this.

4 REPLIES 4
PaigeMiller
Diamond | Level 26

&sysdate is read only. You can't modify it.

 

Use a different name, and that should work

 

%let sysdate1 = %eval(%sysfunc(today())-4);
--
Paige Miller
Tom
Super User Tom
Super User

I don't think you can do that (and you really shouldn't even if you could).

Instead write your code using your own macro variable.  You can default to the date the session started if you want.

Say you decide to use RUNDATE as the name of your macro variable.  In your normal code just use something like this to set the value when not provide.

%if 0=%length(&rundate) %then %let rundate=&sysdate9;

PS You should never use only two digits for the year in a date. So always use SYSDATE9 and not SYSDATE.

 

Then in your test runs just set RUNDATE before the code to be tested.

%let rundate=%sysfunc(putn("&sysdate9"d-4,date9.));
ballardw
Super User

It's not nice to fool with system supplied variables. And SAS explicitly will not allow to change this one.

 

Make your own instead of attempting to modify a system variable like this.

 

The macro language is very literal. If you want to use a function that is not a macro language specific function then you call it using the %sysfunc function:

 

%let example = %eval (%sysfunc(Today()) -4);

Would assign the numeric date value of 4 days prior to Example. The %eval is required to do subtraction. Or nest the today function inside an Intnx function call to do similar:

%let example2 = %sysfunc(intnx('day',%sysfunc(today()),-4));

You would need yet more code if you want it in the date7. format that &sysdate uses.

TomKari
Onyx | Level 15

Along with the other excellent replies, let me suggest that you NEVER name a macro variable beginning with "sys". This prefix is used for SAS system variables, and I guarantee you will CONFUSE THE HECK out of some poor devil who needs to support your program!

 

Tom

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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