|
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.
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:
- If the dates in your data fall within a 100-year
span, you can use the YEARCUTOFF= system option.
- If the dates in your data do not fall within a
100-year span, you must either convert the two-digit years to to four-digit
years or use a DATA step with conditional logic to assign the proper century
prefix.
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
- 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
00 through 19 as 2000 through 2019.
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
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:
- In the datalines in the DATA step, the first record
contains a two-digit year of 25, and the second record contains a four-digit
year of 2025. Because the YEARCUTOFF= system option is set to 1920, the two-digit
year defaults to a year in the 1900s in observation number 1. The four-digit
year in observation number 2 is unaffected by the YEARCUTOFF= option.
- The third record is similar to the first and defaults
to a year in the 1900s based on the value of YEARCUTOFF=.
- The output from records 4 and 5 shows results
that are similar to records 1 and 2. The fourth record specifies a two-digit
year of 00, and the fifth one specifies a four-digit year of 2000. Because
of the value of the YEARCUTOFF= option, the years in the two resulting observations
are the same.
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.
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.