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.);
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.