Table of Contents
SAS (Statistical Analysis System) is a software suite used for data management, analysis, and reporting. One of its key functionalities is the ability to display values in time format, which is particularly useful in time series analysis and forecasting.
To display values in time format using SAS, the user must first convert the data into SAS time values. This can be achieved by using the SAS format functions or by specifying the appropriate SAS informat for the data. Once the data is converted, the user can then use the SAS time formats to display the values in a desired format, such as hours, minutes, seconds, or a combination of these.
Additionally, SAS provides a wide range of options for customizing the display of time values, such as specifying the starting time point, the increment between time values, and the time interval to be displayed. This allows for greater flexibility and accuracy in presenting time data in various formats.
In summary, SAS offers a comprehensive and efficient solution for displaying values in time format, making it a valuable tool for data analysis and reporting in various industries.
SAS: Display Values in Time Format
Suppose you have a variable in SAS called duration that has a time value of 7:30:00.
You can use the following functions in SAS to format this time value in different ways:
- PUT(duration, time8.) – Format as time with a total length of 8.
- This will produce 7:30:00.
- PUT(duration, hhmm.) – Format as time with only hours and minutes.
- This will produce 7:30.
- PUT(duration, hours5.2) – Format as time with decimal hours.
- This will produce 7.50.
- hour(duration) – Format as hours only.
- This will produce 7
- minute(duration) – Format as minute only.
- This will produce 30.
- second(duration) – Format as seconds only.
- This will produce 0.
The following example shows how to use each of these formats in practice.
Example: Display Values in Time Formats in SAS
Suppose we have the following dataset in SAS that contains information about the duration that it took various athletes to finish some task:
/*create dataset*/
data my_data;
input athlete $ duration time8.;
datalines;
A 04:15:00
B 10:09:15
C 7:30:00
D 18:55:00
E 14:23:59
F 23:45:10
;
run;
/*view dataset*/
proc printdata=my_data;

By default, SAS stores time values as seconds.
For example, in the first line we entered 4 hours, 15 minutes and 0 seconds, which is equivalent to 15,300 seconds.
Note: There are 86,400 seconds in one day.
We can use the following syntax to create a new dataset in which we format the values in the duration column in different time formats:
/*create new dataset with duration printed in various time formats*/
data new_data;
set my_data;
duration_time8 = put(duration, time8.);
duration_hhmm = put(duration, hhmm.);
duration_hour52 = put(duration, hour5.2);
duration_hour = hour(duration);
duration_minute = minute(duration);
duration_second = second(duration);
run;
/*view new dataset*/
proc printdata=new_data;
Notice that each of the new columns format the time values in a different way:
- duration_time8 displays hours, minutes and seconds.
- duration_hhmm displays only hours and minutes.
- duration_hhmm displays decimal hours.
- duration_hour displays only the hour value.
- duration_minute displays only the minute value.
- duration_second displays only the seconds value.
Feel free to use whichever format you’d like based on how you would like to display time values in your dataset.
The following tutorials explain how to perform other common tasks in SAS:
Cite this article
stats writer (2024). How can values be displayed in time format using SAS?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-values-be-displayed-in-time-format-using-sas/
stats writer. "How can values be displayed in time format using SAS?." PSYCHOLOGICAL SCALES, 23 Jun. 2024, https://scales.arabpsychology.com/stats/how-can-values-be-displayed-in-time-format-using-sas/.
stats writer. "How can values be displayed in time format using SAS?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-values-be-displayed-in-time-format-using-sas/.
stats writer (2024) 'How can values be displayed in time format using SAS?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-values-be-displayed-in-time-format-using-sas/.
[1] stats writer, "How can values be displayed in time format using SAS?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, June, 2024.
stats writer. How can values be displayed in time format using SAS?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.
