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
SAS Super FREQ

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
SAS Super FREQ

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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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