BookmarkSubscribeRSS Feed
Rasmi_sas
Calcite | Level 5

I have account_opened_date variable contains accounts opened dates. For example accounts which are opened in the year 1914, 2006 and 2021, how can I print the date values in the output with or without using yearcutoff

3 REPLIES 3
SASJedi
Ammonite | Level 13

If your dates are stored as numeric values, you should be able to print them properly by applying the desired format like mmyydd10. or date9.  If your dates are stored as text without century information, like '01/01/15' or '01JAN15' then you will either have to identify the specific YEARCUTOFF value that applies to your data, or find some way of identifying the correct century from other information in the record. 

Check out my Jedi SAS Tricks for SAS Users
Cynthia_sas
Diamond | Level 26

Hi:

  You may have a different setting for YEARCUTOFF than on my system. Here's a test program you can run. Note that the data in the 2 programs is the same. The only difference is whether there is a 4 digit year or a 2 digit year in the datalines:

proc options option=yearcutoff;
run;

** GRP var indicates century a=1800, b=1900, c=2000

** with 4 digit years in data;
data create4;
  infile datalines dlm=',';
  input grp $ date : date.;
  putlog _n_= grp= date= mmddyy10.;
datalines;
a,01jan1800
b,01jan1900
b,01jan1960
b,01jan1970
b,01jan1980
c,01jan2000
c,01jan2010
c,01jan2022
;
run;

** with 2 digit years in data;
data create2;
  infile datalines dlm=',';
  input grp $ date : date.;
  putlog _n_= grp= date= mmddyy10.;
datalines;
a,01jan00
b,01jan00
b,01jan60
b,01jan70
b,01jan80
c,01jan00
c,01jan10
c,01jan22
;
run;

 As you can see, with a 4 digit year in the data, as shown below, there is NOT any issue. The issue is with the 2 digit years:

Cynthia_sas_0-1654690209738.png

  I always recommend to my students that they request 4 digit years when they get data or design data inputs for date values and that they always use 4 digit years to display date values. Since SAS internally stores a date as an offset from 0, as long as you read date values with 4 digit years or you create variable values with 4 digit years, your dates should be OK and can go as far back as the start of the Gregorian calendar (1580+). Yearcutoff comes into play when you only have 2 digit years. Usually dates don't span more than 100 year span so your 2 digit years MIGHT work fine for you. But, as shown above, you can have issues when your dates do span more than 100 years. Here's a very good explanation of the issues you run into when your dates span more than 100 years: https://blogs.sas.com/content/sgf/2020/01/10/yearcutoff-date/

 

Cynthia

ballardw
Super User

@Rasmi_sas wrote:

I have account_opened_date variable contains accounts opened dates. For example accounts which are opened in the year 1914, 2006 and 2021, how can I print the date values in the output with or without using yearcutoff


Yearcutoff basically only affects how SAS treats 2-digit years when reading values with input statements or function and/or Proc Import.

 

If you are reading data with 2-digit years then show an example of the text file you are reading. Copy some lines of text and then on the forum open a text box using the </> icon above the message window and paste the text. Note: pasting text directly into the message windows will reformat text and may not appear correctly.

 

If the variables are already SAS date values then any format that displays 4-digit years such as DATE9., MMDDYY10., YEAR4. will display the year.

 

Details, details, details.

Run Proc Contents on your data set and show us the result. If the name of your "date" variable(s) is not obvious tell which it is and we may be able to provide more specific help.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 767 views
  • 4 likes
  • 4 in conversation