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.


Difference between revisions of "Tips:Displaying a time value as a duration"

From sasCommunity
Jump to: navigation, search
m (gardening)
m (gardening)
 
Line 1: Line 1:
 
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.
 
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:
+
In SAS Release 9.3, there is a new time directive for PICTURE [[statements]] that provides this facility:
 
<source lang="sas">
 
<source lang="sas">
 
1    proc format;
 
1    proc format;
Line 26: Line 26:
 
       cpu time            0.01 seconds
 
       cpu time            0.01 seconds
 
</source>
 
</source>
<!-- Insert any appropriate category tags. Note that it is important to put the categorys inside the <noinclude> block so the categories are only applied to the tip page.
 
- You can have as many CATEGORY tag lines as you want.
 
-->
 
  
<!-- Provide links to other resources:
+
 
- If the links are pages on sasCommunity update the "WikiReadMore" line and replace "PAGENAME" with the name of the sasCommunity.org page.
+
- If the links are external (e.g., the sas support site, other external links, and so on, updated the "External ReadMore" line and replace "URL" with the full url including the http:
+
- You can include as many of these lines as you want
+
- if you don't have such links, just delete the line(s)
+
-->
+
 
{{ExternalReadMore|http://support.sas.com/documentation/cdl/en/proc/63079/HTML/default/viewer.htm#p0n990vq8gxca6n1vnsracr6jp2c.htm}}
 
{{ExternalReadMore|http://support.sas.com/documentation/cdl/en/proc/63079/HTML/default/viewer.htm#p0n990vq8gxca6n1vnsracr6jp2c.htm}}
 
<!-- Please do not edit below this line, EXCEPT when promoting a tip -->
 
<!-- Please do not edit below this line, EXCEPT when promoting a tip -->
Line 41: Line 33:
  
 
<noinclude>
 
<noinclude>
[[Category:Tip in Use]]
 
 
[[Category:FORMAT Procedure]]
 
[[Category:FORMAT Procedure]]
 
[[Category:PICTURE Statement]]
 
[[Category:PICTURE Statement]]
 +
[[Category:Tip in Use]]
 
</noinclude>
 
</noinclude>

Latest revision as of 14:24, 27 September 2017

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