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
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.