As the first step in the decommissioning of sasCommunity.org the site has been converted to read-only mode.


Here are some tips for How to share your SAS knowledge with your professional network.


Tips:Displaying a time value as a duration

From sasCommunity
Jump to: navigation, search

The SAS TIME. format will format a time value as hours:minutes:seconds and will handle the case where the value is a duration greater than 24 hours. But when the number of hours is greater than 24, it might be preferred to display the value as days:hours:minutes:seconds where hours is 0-23.

In SAS Release 9.3, there is a new time directive for PICTURE statements that provides this facility:

1    proc format;
2     picture duration low-high = '%n:%0H:%0M:%0S' (datatype=time);
NOTE: Format DURATION has been output.
3    run;
 
NOTE: PROCEDURE FORMAT used (Total process time):
      real time           0.11 seconds
      cpu time            0.00 seconds
 
4    data _null_;
5     /* create a variable whose value is duration since the beginning of the current month */
6     duration = datetime() - mdy(month(today()),1,year(today()))*24*60*60;
7     put 'In Days:Hours:Minutes:Seconds: ' duration duration. /
8         'In Hours:Minutes:Seconds: ' duration time9.;
9    run;
 
In Days:Hours:Minutes:Seconds: 10:12:34:07
In Hours:Minutes:Seconds: 252:34:07
 
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


....see also

Submitted By Don Henderson