Chapter Contents |
Previous |
Next |
Working with Time Series Data |
Dates represented in this way are called SAS date values. Any numeric variable in a SAS data set whose values represent dates in this way is called a SAS date variable.
Representing dates as the number of days from a reference date makes it easy for the computer to store them and perform calendar calculations, but these numbers are not meaningful to users. However, you never have to use SAS date values directly, since SAS automatically converts between this internal representation and ordinary ways of expressing dates, provided that you indicate the format with which you want the date values to be displayed. (Formatting of date values is explained in a following section.)
For example, SAS reads the value '17OCT1991'D the same as 11612, the SAS date value for 17 October 1991. Thus, the following SAS statements print DATE=11612.
data _null_; date = '17oct1991'd; put date=; run;
The year value can be given with two or four digits, so '17OCT91'D is the same as '17OCT1991'D. (The century assumed for a two-digit year value can be controlled with the YEARCUTOFF= option in the OPTIONS statement. Refer to the SAS Language: Reference for information on YEARCUTOFF=.)
To specify datetime constants in a SAS program, write the date and time in single quotes followed by DT. To write the date and time in a SAS datetime constant, write the date part using the same syntax as for date constants, and follow the date part with the hours, the minutes, and the seconds, separating the parts with colons. The seconds are optional.
For example, in a SAS program you would write 17 October 1991 at 2:45 in the afternoon as '17OCT91:14:45'DT. SAS reads this as 1003329900. Table 2.1 shows some other examples of datetime constants.
Table 2.1: Examples of Datetime ConstantsDatetime Constant | Time |
'17OCT1991:14:45:32'DT | 32 seconds past 2:45 p.m., 17 October 1991 |
'17OCT1991:12:5'DT | 12:05 p.m., 17 October 1991 |
'17OCT1991:2:0'DT | 2 AM, 17 October 1991 |
'17OCT1991:0:0'DT | midnight, 17 October 1991 |
SAS time values are not very useful for identifying time series, since usually both the date and the time of day are needed. Time values are not discussed further in this book.
Chapter Contents |
Previous |
Next |
Top |
Copyright © 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.