BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
SeaMoon_168
Quartz | Level 8

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

SeaMoon_168_0-1712178798367.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

Try this:

%let X = 01Jan2021; 
%let X_new = %sysfunc(INTNX(DAY,"&x"d,31), date9.);
%put &X_new;

View solution in original post

3 REPLIES 3
Quentin
Super User

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;

 

SASKiwi
PROC Star

Try this:

%let X = 01Jan2021; 
%let X_new = %sysfunc(INTNX(DAY,"&x"d,31), date9.);
%put &X_new;
Tom
Super User Tom
Super User

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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1120 views
  • 4 likes
  • 4 in conversation