05-03-2018 02:30 PM
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
05-03-2018 03:21 PM
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)
05-03-2018 03:28 PM
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.