Chapter Contents

Previous

Next

How SAS Handles Dates


How SAS Stores Date Values

To evaluate your SAS code for Year 2000 compliance (and to understand why SAS software itself is compliant), it is helpful to understand how SAS software processes date values. The SAS System stores date values as an offset in days from January 1, 1960, and it stores datetime values (such as 23FEB98:16:30) as an offset in seconds from midnight January 1, 1960.

Dates and times converted to SAS date and datetime values in this manner may be used more easily in numeric calculations, and there is no ambiguity as to which century a SAS date or datetime value is associated with.

For more information about how the SAS system handles dates, see the section on dates, times and datetime values.


How SAS Converts External Date Information to Internal Representation

You can convert external data to or from SAS date values and datetime values by using SAS informats, formats, and functions. Most of these features accept two-digit years as well as four-digit years. For example, if your input file contains a date value of '07/27/1998', you can read it using the MMDDYY10. informat, while a field containing '07/27/98' can be read using either the MMDDYY8. informat or the MMDDYY10 informat. Similarly, dates with four and two-digit years can be written to external files using the MMDDYY10. and MMDDYY8. formats respectively.


How to Read Two-Digit Years Using YEARCUTOFF=

If dates in your external data sources or SAS program statements contain two-digit years, 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:

Once you've 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 a year just slightly lower than the lowest year in your data. For example, if you have data in a range from 1921 to 1999, set YEARCUTOFF= to 1920, if that is not already your system default. The result of setting YEARCUTOFF= to 1920 is that

The following figure shows the span of years when the YEARCUTOFF= option is set to a value of 1920. The 100-year span in this case is from 1920 to 2019.

Span of Years When the YEARCUTOFF= Option Is Set to 1920

[IMAGE]

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.

Here are some other helpful facts to know when using the YEARCUTOFF= system option:


Example 1: How YEARCUTOFF= Affects Two and Four-Digit Years

The following example shows what happens with data that contains both two and four-digit years. Note how the YEARCUTOFF= option is set to 1920.

options yearcutoff=1920 nodate pageno=1 linesize=80 pagesize=60;

data schedule;
   input @1 jobid $ @6 projdate mmddyy10.;
   datalines;
A100 01/15/25
A110 03/15/2025
A200 01/30/96
B100 02/05/00
B200 06/15/2000
 ;

proc print data=schedule;
   format projdate mmddyy10.;
run;  

The resulting output from the PROC PRINT statement looks like this:

Output from The Previous DATA Step Showing 4-Digit Years That Result from Setting YEARCUTOFF= to 1920
                                 The SAS System         1

                           Obs    jobid      projdate

                            1     A100     01/15/1925
                            2     A110     03/15/2025
                            3     A200     01/30/1996
                            4     B100     02/05/2000
                            5     B200     06/15/2000

Here are some facts to note in this example:

As you can see, specifying a two-digit year may or may not result in the intended century prefix. The optimal value of the YEARCUTOFF= option depends on the range of the dates that you are processing.

In Releases 6.06 through 6.12 of the SAS System, the default value for the YEARCUTOFF= system option is 1900; in Version 7 and Version 8, the default value is 1920.

For more information on how SAS handles dates, see the section on dates, times and datetime values.


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.