BookmarkSubscribeRSS Feed
suresh123
Calcite | Level 5

Iam trying to get the next month of a date.

 

 

%let date =2017-01-12;
%let et=%sysfunc(intnx(month,&date.,1),yymmdd10.);
%put &et.;

 

But result is different. What went wrong

1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 61         
 62         %put &et.;
 1965-07-01
 63         
 64         OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 77         

 

4 REPLIES 4
novinosrin
Tourmaline | Level 20

Try this

%let date =2017-01-12;
%let et=%sysfunc(intnx(month,%sysfunc(inputn(&date.,yymmdd10.)),1),yymmdd10.);
%put &et.;
novinosrin
Tourmaline | Level 20

For same dates instead of 1st of month-->

%let date =2017-01-12;
%let et=%sysfunc(intnx(month,%sysfunc(inputn(&date.,yymmdd10.)),1,s),yymmdd10.);
%put &et.;
Reeza
Super User

SAS dates need to be specified as date literals to be automatically recognized as dates. 

 

How is the compiler supposed to know if you want 2017-01-12 = 2017-1-12 = 2017-13=2004

or that it's a date?

 

The way to do that is specify dates in a date literal format:

 

%let date = '12Jan2017'd;
%let et=%sysfunc(intnx(month,&date.,1),yymmdd10.);
%put &et.;

This works. If you want to specify the date in a different format, then YOU need to handle the conversion, which is demonstrated in @novinosrin code using the INPUTN()  function. (INPUT() does not work with %SYSFUNC, but INPUTN() does)

Kurt_Bremser
Super User

2017-01-12 used as a date parameter will be evaluated as 2004 (2017 minus 1 minus 12), which means 2004 days after 01jan1960.

Use a proper informat as @novinosrin suggests.

Hint: macro variables to be used as dates should contain raw date values (5-digit numbers as of now); human-readable form is not needed. Makes everything easier.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 4 replies
  • 1830 views
  • 1 like
  • 4 in conversation