yyyymm convert to full sas date (dd/mm/ccyy) - SAS

后端 未结 1 1593
离开以前
离开以前 2021-01-20 15:11

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

1条回答
  •  一向
    一向 (楼主)
    2021-01-20 16:07

    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
    

    0 讨论(0)
提交回复
热议问题