I would like to set a variable so that proc format always subtracts 3 years from today (). Date_old should be substract todaty_date - 3 years and given 2019 for example This is my code:
%let date_old=%sysfunc(YEAR(Today()-3), yymmd7.); proc format; value date_less low-'date_old' = 'Exp' other=[yymmd7.]; run;
But i see error on log :
NOTE: Writing HTML5(EGHTML) Body file: EGHTML
ERROR: Required operator not found in expression: Today()-4
ERROR: Argument 1 to function YEAR referenced by the %SYSFUNC or %QSYSFUNC macro function is not a number.
ERROR: Invalid arguments detected in %SYSCALL, %SYSFUNC, or %QSYSFUNC argument list. Execution of %SYSCALL statement or %SYSFUNC
or %QSYSFUNC function reference is terminated.
27
To compute &date_old, use
%let date_old=%sysfunc(intnx(year,%sysfunc(Today()),-3));
%put &=date_old;
Note that %sysfunc has to be called twice, once to make use of the INTNX function and once to make use of the TODAY() function.
The above code produces a result which is the first day of the year, I don't know if that's really what you want, you didn't actually say what day of the year you want.
For your PROC FORMAT, you do not need (and should not use) formatted macro variables (you rarely need formatted macro variables unless the macro variable is to be used in a title, label or file name).
proc format;
value date_less low-&date_old = 'Exp' other=[yymmd7.];
run;
To compute &date_old, use
%let date_old=%sysfunc(intnx(year,%sysfunc(Today()),-3));
%put &=date_old;
Note that %sysfunc has to be called twice, once to make use of the INTNX function and once to make use of the TODAY() function.
The above code produces a result which is the first day of the year, I don't know if that's really what you want, you didn't actually say what day of the year you want.
For your PROC FORMAT, you do not need (and should not use) formatted macro variables (you rarely need formatted macro variables unless the macro variable is to be used in a title, label or file name).
proc format;
value date_less low-&date_old = 'Exp' other=[yymmd7.];
run;
You function call is not correct. Whet you will get with YEAR(TODAY()-4 is 2021-4, that is 2017. If you format that as a date, you will get a date that is 2017 days from 01JAN1960.
Instead, use the INTNX function:
%let date_old=%sysfunc(intnx(year,"&sysdate9."d,-4), yymmd7.)
Instead of the TODAY function, I used the automatic variable SYSDATE9, which contains the date that the SAS system was started (would normally be today).
If you must use the TODAY function, you must enclose that in as %SYSFUNC call as well:
%let date_old=%sysfunc(intnx(year,%sysfunc(TODAY()),-4), yymmd7.);
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!
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.