22.4 - SAS Date System Options

There are two system options that affect how SAS handles dates —the DATESTYLE= and YEARCUTOFF= options.

The DATESTYLE= system option tells SAS your intended sequence of month (M), day (D), and year (Y) when dates are ambiguous. Possible settings include MDY, MYD, YMD, YDM, DMY, DYM, and LOCALE. By default, the DATESTYLE system option is set to LOCALE, which tells SAS to use the form of dates that reflect the language and local conventions of the geographical region specified by the LOCALE system option. Yikes, this sounds circular! Because LOCALE is by default set to ENGLISH for users in the United States, MDY is our default DATESTYLE option. We won't spend any more time on the DATESTYLE system option, but it is something you'll definitely want to know about if you ever get tempted to use the anydtdte. informats to read in dates. (Even though the anydtdte. informats are tempting to use as they allow you to read in different forms of the same date into one date variable, I chose not to present the informat, because I don't like the way it makes SAS have to make decisions about my data!)

SAS developed the YEARCUTOFF= system option to provide users with a way to handle two-digit years. If we specify the date constant '13apr08'd, we could mean 2008, 1908, or even 1808. The YEARCUTOFF = system option eliminates this ambiguity by telling SAS the first year of a 100-year span to be used by date informats and functions when SAS encounters a two-digit year. The default value of YEARCUTOFF is 1920. In the default case, if SAS encounters a two-digit year in your program between 20 and 99, SAS assumes the date has a prefix of 19. And, if SAS encounters a two-digit year in your program between 00 and 19, SAS assumes the date has a prefix of 20. There are two things you can do if you don't like the way SAS is handling your two-digit dates — either use four-digit dates or use the OPTIONS statement to change the default YEARCUTOFF= option. We'll take a look at two examples now just to make sure we understand how SAS handles two-digit years.

Example 22.17 Section

The following SAS program uses the default YEARCUTOFF = 1920 to read in nine dates that contain two-digit years ranging from 20 to 99, and then from 00 to 19:

OPTIONS YEARCUTOFF=1920;
DATA twodigits1920;
    INPUT date1 mmddyy8.;
    FORMAT date1 worddatx20.;
    DATALINES;
01/03/20
01/03/21
01/03/49
01/03/50
01/03/51
01/03/99
01/03/00
01/03/01
01/03/19
    ;
RUN;
 
PROC PRINT data=twodigits1920;
    title 'Years with two-digits when YEARCUTOFF = 1920';
RUN;

Years with two-digits when YEARCUTOFF = 1920
Obsdate1
13 January 1920
23 January 1921
33 January 1949
43 January 1950
53 January 1951
63 January 1999
73 January 2000
83 January 2001
93 January 2019

First, review the dates in the DATALINES statement to make sure you understand the range of two-digit years that we are trying to read into the twodigits1920 data set. Then, launch and run  the SAS program, and review the resulting output. Note that the dates containing two-digit years between 20 and 99 are displayed as four-digit years between 1920 and 1999. And, the dates containing two-digit years between 00 and 19, are displayed as four-digit years between 2000 and 2019.

Example 22.18 Section

The following SAS program is identical to the previous program except the YEARCUTOFF= system option has been changed to 1950. As before, SAS reads in nine dates that contain two-digit years ranging from 20 to 99, and then from 00 to 19:

OPTIONS YEARCUTOFF=1950;
 
DATA twodigits1950;
    INPUT date1 mmddyy8.;
    FORMAT date1 worddatx20.;
    DATALINES;
01/03/20
01/03/21
01/03/49
01/03/50
01/03/51
01/03/99
01/03/00
01/03/01
01/03/19
    ;
RUN;
 
PROC PRINT data=twodigits1950;
    title 'Years with two-digits when YEARCUTOFF = 1950';
RUN;

Years with two-digits when YEARCUTOFF = 1950
Obsdate1
13 January 2020
23 January 2021
33 January 2049
43 January 1950
53 January 1951
63 January 1999
73 January 2000
83 January 2001
93 January 2019

Again, review the dates in the DATALINES statement to make sure you understand the range of two-digit years that we are trying to read into the twodigits1950 data set. Then, launch and run  the SAS program, and review the resulting output. Note that now the dates containing two-digit years between 50 and 99, are displayed as four-digit years between 1950 and 1999. And, the dates containing two-digit years between 00 and 49, are displayed as four-digit years between 2000 and 2049.