I tried to run the code to add one month to X='01Jan2021'd.
First, I am not sure if I need to add inputc for X
Second, the code cannot work
%let X='01Jan2021'd;
%let Xnew = %sysfunc(INTNX('day',%sysfunc(inputc(&X,date9.)),31) date9.);
%put &X_new;
Howover, I got the error message
WARNING: Argument 2 to function INPUTC referenced by the %SYSFUNC or %QSYSFUNC macro function is out
of range.
ERROR: Expected close parenthesis after macro function invocation not found.
3 %put &X_new;
WARNING: Apparent symbolic reference X_NEW not resolved.
&X_new
Try this:
%let X = 01Jan2021;
%let X_new = %sysfunc(INTNX(DAY,"&x"d,31), date9.);
%put &X_new;
Your date is a date literal, you don't need to use the INPUT function to convert it. Also, you don't need quotation marks around month because you are calling INTNX as part of the macro language, and the macro language doesn't use quotes to mark text. And you were missing a comma.
Try:
%let X='01Jan2021'd;
%let Xnew = %sysfunc(INTNX(month,&x,1), date9.);
%put &Xnew;
Try this:
%let X = 01Jan2021;
%let X_new = %sysfunc(INTNX(DAY,"&x"d,31), date9.);
%put &X_new;
Do you want to add one MONTH or 31 days?
If you want to add a month use the MONTH interval.
%let X='01Jan2021'd;
%let Xnew = "%sysfunc(INTNX(month,&X,1),date9.)"d;
If you want to keep the same relative posistion in the month use an alignment value of SAME
If you just want to add 31 days no matter what the then you can just use arithmetic as SAS stores dates as days.
%let X='01Jan2021'd;
%let Xnew = "%sysfunc(putn(&X+31,date9.))"d;
And if you don't need the new date formatted so humans can read it you can just use %SYSEVALF() to do the addition.
%let X='01Jan2021'd;
%let Xnew = %sysevalf(&x+31);
Example:
1 %let X='01Jan2021'd; 2 %let Xnew = "%sysfunc(INTNX(month,&X,1),date9.)"d; 3 %put &=xnew; XNEW="01FEB2021"d 4 5 %let X='01Jan2021'd; 6 %let Xnew = "%sysfunc(putn(&X+31,date9.))"d; 7 %Put &=xnew; XNEW="01FEB2021"d 8 9 %let X='01Jan2021'd; 10 %let Xnew = %sysevalf(&x+31); 11 %Put &=xnew; XNEW=22312
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.