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.);
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: