Jan 7, 2020

How to read 2-digit year properly with YEARCUTOFF SAS options

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.
If you want to check you current default yearcutoff value, run this code:
proc options option=yearcutoff;
run;

You will see something like this(date may be different) as response in SAS Log:


 YEARCUTOFF=1920   Cutoff year for DATE and DATETIME informats and functions

Example:
Before changing default value:
Code:
       data yearTest;
            date='01jan20'd;
           put 'Date= ' date date9.;

        run;
Response in log:
      Date=01JAN1920

After changing default value:
Code:
     options yearcutoff = 1950;
       data yearTest;
            date='01jan20'd;
           put 'Date= ' date date9.;

        run;
Response in log:
      Date=01JAN2020

Your system administrator may change the default to suit specific needs at your work site.





No comments:

Post a Comment