BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
chappy
Calcite | Level 5

I feel crazy for asking this question but what worked last week is not working this week for some reason

I have the following data have:

date

14MAR2004

16MAR2005

11MAR2006

22MAR2007

02MAR2008

19MAR2009

11MAR2010

I would like to create a "year" column from these date which will be equal to the year of the date plus one (for example, for 14MAR2004 the year would be 2005)

I have used the following:

data want; set have;

year= year(date) + 1;

format year year4.;

run;

This has returned the desired year but this morning sas is returning 1965 as the year value for each date value in the column. Am I missing something? The date value has been previously formatted as date9.

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Check your yearcutoff option setting and run a proc contents on your dataset and look at the format and type of your date variable. Make sure its date not datetime.

Old but still relevant for yearcutoff option:

SAS Technical Support News: A GUIDE TO THE YEARCUTOFF= OPTION

View solution in original post

4 REPLIES 4
Reeza
Super User

Check your yearcutoff option setting and run a proc contents on your dataset and look at the format and type of your date variable. Make sure its date not datetime.

Old but still relevant for yearcutoff option:

SAS Technical Support News: A GUIDE TO THE YEARCUTOFF= OPTION

chappy
Calcite | Level 5

Thanks Reeza. I used  "options yearcutoff=1920;"   before the data statement and it worked. The date variable was already formatted to date9.

Thanks again.

art297
Opal | Level 21

Remove the statement that declares the year format for variable year.  The year format expects a date, not a year.

PGStats
Opal | Level 21

I would do it this way :

data have;
format date date9.;
input date :date9.;
datalines;
14MAR2004
16MAR2005
11MAR2006
22MAR2007
02MAR2008
19MAR2009
11MAR2010
;

data want;
set have;
yearDate = intnx("YEAR", date, 1); /* move date by 1 year */
format yearDate year4.;
run;


proc print; run;


if your dates are in fact datetimes then replace "YEAR" by "DTYEAR" and year4. by dtyear4.

PG

PG

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 4 replies
  • 2469 views
  • 0 likes
  • 4 in conversation