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.
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
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
Thanks Reeza. I used "options yearcutoff=1920;" before the data statement and it worked. The date variable was already formatted to date9.
Thanks again.
Remove the statement that declares the year format for variable year. The year format expects a date, not a 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
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: