SAS 9.3 DATETIME VARIABLE FORMAT AS DATE

后端 未结 8 1525
误落风尘
误落风尘 2020-12-18 16:36

I have a datetime22.3 variable which I would like to display as date.

for eg I want to display 17JUL2006:00:00:00.000 as 07/17/2006

How do I do this?

相关标签:
8条回答
  • 2020-12-18 17:21
    data want;
    dt_val1='17JUL2006:00:00:00.000'dt;
    dt_you_want=input(substr(put(dt_val1,datetime22.3),1,9),date9.);
    format dt ddmmyy10.;
    run; 
    
    0 讨论(0)
  • 2020-12-18 17:22

    Formatting dates in SAS can be tricky. One method I've used in a macro is this:

    /* get the date time */
    %let start_date=%sysfunc(datetime().,10);
    /* use the DATETIME informat to format the date */
    %let fmt_start_date=%sysfunc(putn(&start_date, DATETIME.)); 
    /* format the datetime as a date */
    %put "&fmt_start_date."d;
    

    There's a bunch of different ways to format dates. You could also use the FORMAT statement if you're in a data step:

    FORMAT STARTDATE YYMMDD10.;
    

    In this case, the format of the column in the data step would give you YYYY-MM-DD and then you can separate the values and reconstruct from there.

    There's additional information about SAS informats for dates here: http://support.sas.com/documentation/cdl/en/etsug/60372/HTML/default/viewer.htm#etsug_intervals_sect008.htm

    And here: http://support.sas.com/documentation/cdl/en/etsug/63348/HTML/default/viewer.htm#etsug_intervals_sect009.htm

    If you need more info or examples, please let me know.

    Best of luck!

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