Dear Experts;
I had a datetime column for 2016 and i want to update to 2017 without changing the date and month.
Any idea?
data increment;
input @1 dateid @7 datevalues ;
informat datevalues datetime22.;
format datevalues datetime22.;
cards;
28351 01MAY2016:00:00:00.000
28352 02MAY2016:00:00:00.000
28353 03MAY2016:00:00:00.000
28354 04MAY2016:00:00:00.000
;
run;
desired output;
datevalues
01MAY2017:00:00:00.000
02MAY2017:00:00:00.000
03MAY2017:00:00:00.000
04MAY2017:00:00:00.000
thanks
Use INTNX function, with dtyear for the year increment and 's' as the alignment parameter to keep the same date/month.
date_later = intnx('dtyear', datevalues, 1, 's');
@tekish wrote:
Dear Experts;
I had a datetime column for 2016 and i want to update to 2017 without changing the date and month.
Any idea?
data increment;
input @1 dateid @7 datevalues ;
informat datevalues datetime22.;
format datevalues datetime22.;
cards;
28351 01MAY2016:00:00:00.000
28352 02MAY2016:00:00:00.000
28353 03MAY2016:00:00:00.000
28354 04MAY2016:00:00:00.000
;
run;
desired output;
datevalues
01MAY2017:00:00:00.000
02MAY2017:00:00:00.000
03MAY2017:00:00:00.000
04MAY2017:00:00:00.000
thanks
If I understand your need this should do it:
data want; set increment; datevalues = intnx('dtyear',datevalues,1,'S'); run;
Which increments the value by 1 year to the same day in the next year.
There may be issues around Feb 29 though if you have such. It will map to the end of February, ie 28 Feb in 2017.
Ballardw,
It works.
thanks,
@tekish You do not mark your own comment as the solution, you mark the persons post who provided the correct solution. Sometimes that may be your own post, but it's clearly not here.
hahaha @Reeza I love that. It made me laugh at 2:15 AM in Chennai. You know what, I noticed many people do not even mark the solution as answered and this one is all the more funny to have his/her own comment as the solution. lol
Regards,
Naveen Srinivasan
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.