Here's my code
data a;
today=mdy(1,1,2015);
do month=1 to 12;
start_of_month=intnx('r445mon',today,month-1,'s');
end_of_month=intnx('r445mon',today,month-1,'e');
output;
end;
format start_of_month end_of_month date7.;
drop today;
run;
proc print data=a noobs;
run;
which produces the following output, note that I would have expected the end_of_month to be one day before the start of the next month, but month 1 ends on 25JAN15 and month 2 starts on 29JAN15. Why is that? How can I fix this?
start_ | end_of_ | |
month | of_month | month |
1 | 01JAN15 | 25JAN15 |
2 | 29JAN15 | 22FEB15 |
3 | 26FEB15 | 29MAR15 |
4 | 02APR15 | 26APR15 |
5 | 30APR15 | 24MAY15 |
6 | 28MAY15 | 28JUN15 |
7 | 02JUL15 | 26JUL15 |
8 | 30JUL15 | 23AUG15 |
9 | 27AUG15 | 27SEP15 |
10 | 01OCT15 | 25OCT15 |
11 | 29OCT15 | 22NOV15 |
12 | 26NOV15 | 03JAN16 |
If you read the definition of the interval: R455MON:
Months that start on the 1st, 5th,9th, 14th, 18th,22nd, 27th, 31st,35th, 40th, 44th,and 48th Monday of the year. The 1st Monday is the Monday on or immediately preceding January 4th.
If you start your program on the 1st Monday of the year which is 29 Dec 2014 then you will get the expected result with the S option which means SAME not start. If you start with another date then use B for BEGINNING:
data a;
today=mdy(1,1,2015);
do month=0 to 11;
start_of_month=intnx('r445mon',today, month,'b');
end_of_month=intnx('r445mon',today, month,'e');
output;
end;
format start_of_month end_of_month date9.;
run;
proc print data=a noobs;
run;
If you read the definition of the interval: R455MON:
Months that start on the 1st, 5th,9th, 14th, 18th,22nd, 27th, 31st,35th, 40th, 44th,and 48th Monday of the year. The 1st Monday is the Monday on or immediately preceding January 4th.
If you start your program on the 1st Monday of the year which is 29 Dec 2014 then you will get the expected result with the S option which means SAME not start. If you start with another date then use B for BEGINNING:
data a;
today=mdy(1,1,2015);
do month=0 to 11;
start_of_month=intnx('r445mon',today, month,'b');
end_of_month=intnx('r445mon',today, month,'e');
output;
end;
format start_of_month end_of_month date9.;
run;
proc print data=a noobs;
run;
Okay, thank you, I see my silly error.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.