Working with Dates in the SAS System |
How SAS Stores Date Values |
Dates are written in many different ways. Some dates contain only numbers, while others contain various combinations of numbers, letters, and characters. For example, all the following forms represent the date July 26, 2000:
072600 | 26JUL00 | 002607 |
7/26/00 | 26JUL2000 | July 26, 2000 |
With so many different forms of dates, there must be some common ground, a way to store dates and use them in calculations, regardless of how dates are entered or displayed.
The common ground that SAS uses to represent dates is called a SAS date value. No matter which form you use to write a date, SAS can convert and store that date as the number of days between January 1, 1960, and the date that you enter. The following figure shows some dates written in calendar form and as SAS date values:
Comparing Calendar Dates to SAS Date Values
In SAS, every date is a unique number on a number line. Dates before January 1, 1960, are negative numbers; those after January 1, 1960, are positive. Because SAS date values are numeric variables, you can sort them easily, determine time intervals, and use dates as constants, as arguments in SAS functions, or in calculations.
Note: SAS date values are valid for dates based on the Gregorian calendar from A.D. 1582 through A.D. 19,900. Use caution when working with historical dates. Although the Gregorian calendar was used throughout most of Europe from 1582, Great Britain and the American colonies did not adopt the calendar until 1752.
Determining the Century for Dates with Two-Digit Years |
If dates in your external data sources or SAS program statements contain two-digit years, then you can determine which century prefix should be assigned to them by using the YEARCUTOFF= system option. The YEARCUTOFF= system option specifies the first year of the 100-year span that is used to determine the century of a two-digit year.
Before you use the YEARCUTOFF= system option, examine the dates in your data:
If the dates in your data fall within a 100-year span, then you can use the YEARCUTOFF= system option.
If the dates in your data do not fall within a 100-year span, then you must either convert the two-digit years to four-digit years or use a DATA step with conditional logic to assign the proper century prefix.
After you have determined that the YEARCUTOFF= system option is appropriate for your range of data, you can determine the setting to use. The best setting for YEARCUTOFF= is the year before the lowest year in your data. For example, if you have data in a range from 1921 to 2001, then set YEARCUTOFF= to 1920, if that is not already your system default. The result of setting YEARCUTOFF= to 1920 is that
SAS interprets all two-digit dates in the range of 20 through 99 as 1920 through 1999.
SAS interprets all two-digit dates in the range of 00 through 19 as 2000 through 2019.
With YEARCUTOFF= set to 1920, a two-digit year of 10 would be interpreted as 2010 and a two-digit year of 22 would be interpreted as 1922.
Copyright © 2012 by SAS Institute Inc., Cary, NC, USA. All rights reserved.