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.);
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.