Working with Time Series Data |
Computing Calendar and Time Variables |
The functions HOUR, MINUTE, and SECOND compute time variables from SAS datetime values. The DATEPART function and the date-to-calendar variables functions can be combined to compute calendar variables from datetime values.
For example, suppose the date and time of the tri-hourly temperature data in the preceding example were recorded as datetime values in the datetime format. The following statements show how to compute the YEAR, MONTH, DAY, and HOUR of each observation and include these variables in the SAS data set:
data weather; input datetime : datetime13. temp; format datetime datetime10.; hour = hour( datetime ); date = datepart( datetime ); year = year( date ); month = month( date ); day = day( date ); datalines; 16oct91:21:00 61 17oct91:00:00 56 17oct91:03:00 53 ... more lines ...
Copyright © SAS Institute, Inc. All Rights Reserved.