Biostat Macro Library
Find the last day of the month
* last day of the month(LDOM) = First day of next month -1;
* LastDayInMonth=mdy(month(adate)+1,1,year(adate))-1;
* Oops, dosen't work for December;
* if month=12 then LDOM=mdy(13,1,year)-1; *Invalid Date!;
* For December, next month=1 and year shold be incremented!;
* Try again adjusting month & year for december;
* To increment month: mod(month(adate),12)+1 (1-11=>2-12, 12=>1);
* To increment year: int(month(adate)/12.0) (1-11=>0, 12=>1);
%Macro endofmonth(adate,endofmonth);
&endofmonth=Mdy(Mod(Month(&adate),12)+1,1,Year(&adate)+Int(Month(&adate)/12.0))-1;
%Mend endofmonth;
Data work.B;
Set work.A;
%endofmonth(anydate,lastday);
Format anydate lastday Date9.;
Run;
|