Chapter Contents |
Previous |
Next |
Working with Time Series Data |
The SAS System provides formats to convert the internal representation of date and datetime values used by SAS to ordinary notations for dates and times. Several different formats are available for displaying dates and datetime values in most of the commonly used notations.
A SAS format is aan instruction that converts the internal numerical value of a SAS variable to a character string that can be printed or displayed. Date formats convert SAS date values to a readable form; datetime formats convert SAS datetime values to a readable form.
In the preceding example, the variable DATE was set to the SAS date value for the first day of the month for each observation. If the data set USCPI were printed or otherwise displayed, the values shown for DATE would be the number of days since 1 January 1960. (See the "DATE with no format" column in Figure 2.2.) To display date values appropriately, use the FORMAT statement.
The following example processes the data set USCPI to make several copies of the variable DATE and uses a FORMAT statement to give different formats to these copies. The format cases shown are the MONYY7. format (for the DATE variable), the DATE9. format (for the DATE1 variable), and no format (for the DATE0 variable). The PROC PRINT output in Figure 2.2 shows the effect of the different formats on how the date values are printed.
data fmttest; set uscpi; date0 = date; date1 = date; label date = "DATE with MONYY7. format" date1 = "DATE with DATE9. format" date0 = "DATE with no format"; format date monyy7. date1 date9.; run; proc print data=fmttest label; run;
The appropriate format to use for SAS date or datetime valued ID variables depends on the sampling frequency or periodicity of the time series. Table 2.2 shows recommended formats for common data sampling frequencies and shows how the date '17OCT1991'D or the datetime value '17OCT1991:14:45:32'DT is displayed by these formats.
Table 2.2: Formats for Different Sampling FrequenciesID values | Periodicity | FORMAT | Example |
---|---|---|---|
SAS Date | Annual | YEAR4. | 1991 |
Quarterly | YYQC6. | 1991:4 | |
Monthly | MONYY7. | OCT1991 | |
Weekly | WEEKDATX23. | Thursday, 17 Oct 1991 | |
DATE9. | 17OCT1991 | ||
Daily | DATE9. | 17OCT1991 | |
SAS Datetime | Hourly | DATETIME10. | 17OCT91:14 |
Minutes | DATETIME13. | 17OCT91:14:45 | |
Seconds | DATETIME16. | 17OCT91:14:45:32 |
See Chapter 3 for more information on the date and datetime formats available.
Chapter Contents |
Previous |
Next |
Top |
Copyright © 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.