I am trying to get the last day of the month from a field numeric in SAS (ccyymm
).
for example 201401 would be 31-01-2014.
I have managed to get
Note the difference between how one would convert a yyyymm to "last day of the month"MMMYYYY format below, depending on whether yyyymm is character or numeric variable.
data test;
yyyymm_character='201401';
yyyymm_numeric=201401;
date1=intnx('month', input(yyyymm_character, yymmn6.), 1)-1;
date2=intnx('month', input(put(yyyymm_numeric,6.), yymmn6.), 1)-1;
format date1 date2 date9.;
/*date1=date2=31jan2014*/
run;
Alternatively, you can use the in-built options for intnx
functions to automatically set any input date to the last day of the respective month. Use 'e'
as shown below.
data test;
yyyymm_character='201401';
yyyymm_numeric=201401;
date1=intnx('month', input(yyyymm_character, yymmn6.), 0, 'e');
date2=intnx('month', input(put(yyyymm_numeric,6.), yymmn6.), 0,'e');
format date1 date2 date9.;
/*date1=date2=31jan2014*/
run