2

Can anyone suggest the best SAS format for a difference in time?

From what I can tell the TIMEw. & HHMMw. & MMSSw. are not appropriate b/c they report time from midnight. I just want to take the number of seconds between to time points and express it in hours, minutes, seconds as appropriate.

flag

3 Answers

3

I would add, however, that you'd want to be careful, since your time1 and time2 might not be on the same day.

The function 'INTCK()' determines the number of specified intervals (months, days, minutes, etc.) between two SAS date-times.

c.f. http://support.sas.com/documentation/cdl/en/lrdict/62618/HTML/default/a000212868.htm

and "About Date and Time Intervals" in the language reference.

You could for instance specify:

ElapsedSec=INTCK('second',FromDateTime,ToDateTime);

Leaving you with having to convert seconds to hours, minutes, seconds (for which I'm stumped past 24 hours.)

link|flag
2

If you calculate the time difference as a measure of seconds (diff = time2 - time1) and the difference is less than 24h, then the TIME. format works, it's just used in a different way than intended.

link|flag
2

Time is expressed as a number in seconds, find below a sample program that shows differrent ways to display hour minutes and seconds. Please note that the TIME. format does print leading zero as blank, whereas TOD. prints leadings zeros. The user defined format MYTIME. combines the two to get all leading zeros (the MYTIME. uses "nested" formats)

proc format;
  value myTime
    0 - 36000 = [tod15.]
    36000 - high = [time15.]
  ;
run;

data test;
  do time = 0 to 20*24*3600 by 2750;
    time2 = time;
    time3 = time;
    output;
  end;
  format
    time time12.
    time2 tod15.
    time3 mytime.
  ;
run;
link|flag
nicely done with the hybrid format. – Moderator Jan 7 at 2:44

Your Answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.