How Can I Find a Time Format that Does Not Remove the Leading Zero e.g. Time5
(output printed as 09:36 instead of 9:36)?
(Suggested by Stephen Hoar, Lloyds TSB)
There is currently no time format that puts leading zeros automatically in time values. But there are a number of ways of achieving this, below are some examples.
Create your own custom format using the following syntax. Then format your data values using the user defined format.
proc format ;
picture military other = '%0H:%0M:%0S' (datatype=time) ;
x= '9:36't ;
format x military8. ;
You can also use the TODw.d format which does write leading zeros, but the original value must be a SAS datetime value. To convert your time values to datetime values use the DHMS function. In the DHMS function insert the value: 0 date, 0 hours, 0 minutes, and then the SAS time value as the number of seconds.
Then format the new variable with the TODw.d format and you will have the correct time, including the leading zeros.
format y tod8.;
Have a look at the following Technical Support website for further examples of using Date & Time functions and formats: http://support.sas.com/techsup/sample/functions.html