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

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;

 

BASUG is hosting free webinars Next up: Mark Keintz presenting History Carried Forward, Future Carried Back: Mixing Time Series of Differing Frequencies on May 8. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 3 replies
  • 264 views
  • 4 likes
  • 4 in conversation