This post was kindly contributed by SAS Users - go there to comment and to read the full post. |
In SAS 9.3 and earlier, the default value of the YEARCUTOFF= option is 1920. This default setting could trigger data integrity issues because any 2-digit years of “20” in dates will be assumed to occur in 1920 instead of 2020. If the intended year in the date is 2020, you must set the YEARCUTOFF= option to a value larger than 1920. Of course, the best alternative is to always specify date values with 4-digit years.
Luckily, SAS makes it easy to change the YEARCUTOFF= option so that it works best for your data. The default value for the YEARCUTOFF= option changed in SAS 9.4 to 1926. This change makes it easier for customers who are still using 2-digit years of “20” to make sure that the date is assigned to 2020. Let’s review some of the frequently asked questions that customers ask about how SAS works with 2-digit years.
What is the YEARCUTOFF= option?
The YEARCUTOFF= option lets you specify which century SAS software should assign to dates with 2-digit years.
How do I specify the YEARCUTOFF= option in my SAS programs?
The option is specified in an OPTIONS statement. Here is an example:
options yearcutoff=1930; |
You can also specify the option in an autoexec file or a config file. If you don’t specify the YEARCUTOFF= option, the SAS system default is used. Remember that 1920 is the default for SAS 9.3 and earlier releases and 1926 is the default for SAS 9.4. (For reference, SAS 9.3 was released in 2011. The first release of SAS 9.4 was released in 2013.)
How does the YEARCUTOFF= option work?
The YEARCUTOFF= option specifies the first year of a 100-year window in which all 2-digit years are assumed to occur. For example, if the YEARCUTOFF= option is set to 1920, all 2-digit years are assumed to occur between 1920 and 2019. This means that two-digit years from 20 – 99 are assigned a century prefix of “19” and all 2-digit years from 00 – 19 have a century prefix of “20.”
Which types of date values are affected by the YEARCUTOFF= option?
The YEARCUTOFF= option affects the interpretation of 2-digit years in the following cases:
- Reading date values from external files
- Specifying dates or year values in SAS functions
- Specifying SAS date literals
The YEARCUTOFF= option does not influence the following cases:
- Processing dates with 4-digit years
- Processing dates already stored as SAS date values (the number of days since January 1, 1960)
- Displaying dates with SAS date formats
Which value should I set the YEARCUTOFF= option to?
The optimal value depends on the range of dates in your data. The YEARCUTOFF= option should be set so that the 100-year range encompasses the range of your data values. In general, SAS recommends setting the YEARCUTOFF= option to a value equal to or slightly less than the first year in your data. For example, if the range of dates that you are processing is from 1930 – 2010, a YEARCUTOFF value of 1925 or 1930 would be appropriate. If you set YEARCUTOFF=1925, then all 2-digit years are assumed to be in the 100-year period from 1925 to 2024. If all the dates in your data fall within that range, they will be interpreted correctly.
What do I do if my dates with 2-digit years span more than 100 years?
The YEARCUTOFF= option cannot reliably assign centuries to 2-digit years if the range of dates for a variable is greater than 100 years. If the date ranges for a variable span more than 100 years, you must either specify the dates with 4-digit years or use DATA step logic to assign a century to each year (perhaps based on the value of another variable).
But why does the YEARCUTOFF= option allow only a 100-year span? If the YEARCUTOFF= option allowed for more than a 100-year span, there would be no way to determine which century a 2-digit year should have. For example, let’s assume that YEARCUTOFF=1950 with a 150-year span and your external data file had 2-digit years. In this scenario, your 150-year span would be from 1950 to 2100. Since you have 2-digit years, there would be no way to determine if the year 00 was meant to occur during 2000 or 2100.
How do I change the default setting for all the SAS users at my site?
Setting system default option values is usually done by a site SAS Installation Representative. The recommended method for setting a system default YEARCUTOFF= value is to specify the desired value in the system SAS configuration file. Note that even if you set a default value for all the users at your site, they can override the default value in their SAS programs, in personal autoexec files, in config files, by setting an environment variable, or when invoking SAS software.
How do I change the default setting for my own programs if I want a default that is different from the rest of the users at my site?
You can specify personal default values either in a personal configuration file or in an autoexec file. If you specify the value in a personal configuration file, the syntax depends on your operating system and is the same as that for setting the value in the system-wide configuration file on each system. If you use an autoexec file, you can specify the YEARCUTOFF= option in an OPTIONS statement. Here is an example:
options yearcutoff=1930; |
Additional Resources
- YEARCUTOFF= System Option section in SAS® 9.3 System Options: Reference, Second Edition
- YEARCUTOFF= System Option section in SAS® 9.4 System Options: Reference, Fifth Edition
- SAS Note 46368, “The default value for the YEARCUTOFF= system option has changed in SAS® 9.4 and beyond”
- SAS Note 65307, “You might encounter an issue in which 2-digit year dates have the wrong century in SAS® 9.3 and earlier releases”
Why does my SAS date have the wrong century? was published on SAS Users.
This post was kindly contributed by SAS Users - go there to comment and to read the full post. |