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

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

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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;

 

--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

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;

 

--
Paige Miller
s_lassen
Meteorite | Level 14

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.);

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
  • 2 replies
  • 501 views
  • 2 likes
  • 3 in conversation