&sysdate is read only. You can't modify it.
Use a different name, and that should work
%let sysdate1 = %eval(%sysfunc(today())-4);
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.));
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.
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
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 25. Read more here about why you should contribute and what is in it for you!
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.