formatting year?

Accepted Solution Solved
Reply
Contributor
Posts: 21
Accepted Solution

formatting year?

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.


Accepted Solutions
Solution
‎01-08-2013 12:43 PM
Super User
Posts: 17,750

Re: formatting year?

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


All Replies
Solution
‎01-08-2013 12:43 PM
Super User
Posts: 17,750

Re: formatting year?

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

Contributor
Posts: 21

Re: formatting year?

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

Thanks again.

PROC Star
Posts: 7,356

Re: formatting year?

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

Respected Advisor
Posts: 4,641

Re: formatting year?

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
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 284 views
  • 0 likes
  • 4 in conversation