Search code examples
sasformatdate-format

Change to the date format 2021-03-18 09:30 in SAS


I'd like to change the date format like the below. Just only excluding seconds... How should I do that. Please give me some advice.

data test;
 dt=1927221180;
 dt2=put(dt,NLDATM20.);
run;

* 2021/01/25 19:13:00 ;
* 2021-01-25 19:13      <----- I want it,   "/" -> "-" and no seconds

Solution

  • You can either roll your own format or use a combination of formats as your date format is non-standard.

    data test;
     dt=1927221180;
     dt2=catx(" ", 
              put(datepart(dt), yymmddd10.), 
              put(timepart(dt), hhmm5.));
              
     
    run;
    

    Note that character dates, such as dt2, cannot be used to calculate durations and they won't sort correctly, ie it will sort alphabetically.