Editor's Note: Thanks to sreeram for showing the optional fourth argument to the INTNX function that allows you to specify the alignment when incrementing the date. To find the last day of the month, the alignment should be set to 'END' or 'E'. This will increment the starting date so that it falls on the last day of the month.
Instead of concatenating the '01' to the starting value, the ANYDTDTE informat can be used to create a SAS date from just the year and month. The resulting SAS date will default to the first day of the month. This slight modification has been made to sreeram's original code.
data a;
aeendtc1='2007-09';
aeendtc2=input(aeendtc1,anydtdte7.);
lastDay=intnx ('month',aeendtc2,0,'E');
mydate=put(lastday,yymmdd10.);
run;
proc print;
format aeendtc2 lastday yymmddd10.;
run;
aeendtc1=strip(aeendtc)||"-01"; aeendtc2=input(aeendtc1,yymmdd10.); lastDay=intnx ('month',aeendtc2,0,'E'); mydate=put(lastday,yymmdd10.);
... View more