Return to Archive

SAS Tip of the Month
November 2006

If you have seperate date and a time variables and you want a single datetime variable combining both, the DHMS function is useful, as the following example demonstrates:

    40    data _null_;
    41        startdate='14Mar2005'd;
    42        starttime='05:15't;
    43        startdatetime=dhms(startdate,0,0,starttime);
    44        put startdate= IS8601DA.
    45            starttime= IS8601TM.
    46            startdatetime= IS8601DT.;
    47    run;
    startdate=2005-03-14 starttime=05:15:00 startdatetime=2005-03-14T05:15:00

Using the DHMS function this way enters the time in seconds as input into the function, which is the same value that SAS stores time from midnight.

I do hope you find this month's tip useful.

Updated November 1, 2006