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.);
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.);
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 the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.