Transforming Data with SAS Functions | |
Manipulating SAS Date Values with
Functions |
SAS Date and Time Values
SAS software contains a variety of functions that enable you to work with SAS date values. SAS software stores a date value as the number of days from January 1, 1960, to a given date. For example,
A SAS time value is stored as the number of seconds since midnight. For example,
Consequently, a SAS datetime value is stored as the number of seconds between midnight on January 1, 1960, and a given date and time. For example,
SAS software stores date values as numbers so you can easily sort the values or perform arithmetic computations. You can use SAS date values as you use any other numeric values. data test(keep=name totday); set hrd.temp; TotDay=enddate-begindate; run; |
SAS Data Set Hrd.Temp
City | State | Zip | Phone | BeginDate | EndDate | PayRate | Days | Hours |
CARY | NC | 27513 | 6224549 | 14567 | 14621 | 10 | 11 | 88 |
CARY | NC | 27513 | 6223251 | 14524 | 14565 | 8 | 25 | 200 |
You can display SAS date values in a variety of forms by associating
a SAS
format with the values. For example, the
FORMAT statement below associates the DATE9. format with the variables
BeginDate and EndDate . A portion of the output created
by this PROC PRINT step appears below.
proc print data=hrd.temp; format begindate enddate date9.; run; |
City | State | Zip | Phone | BeginDate |
EndDate |
Pay Rate |
Days | Hours |
CARY | NC | 27513 | 6224549 | 19NOV1999 | 12JAN2000 | 10 | 11 | 88 |
CARY | NC | 27513 | 6223251 | 07OCT1999 | 17NOV1999 | 8 | 25 | 200 |
CHAPEL HILL | NC | 27514 | 9974749 | 22NOV1999 | 30DEC1999 | 40 | 26 | 208 |
RALEIGH | NC | 27612 | 6970450 | 29SEP1999 | 10OCT1999 | 15 | 10 | 80 |
SAS date values are valid for dates based on the Gregorian calendar from
A.D. 1582 through A.D. 20,000.
|
Use caution when working with historical dates. The Gregorian calendar was used throughout most of Europe from 1582, but Great Britain and the American colonies did not adopt the calendar until 1752. |
Copyright © 2002 SAS Institute Inc.,
Cary, NC, USA. All rights reserved.