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

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

1 ACCEPTED SOLUTION

Accepted Solutions
tekish
Quartz | Level 8

Ballardw,

 

It works.

 

thanks,

 

View solution in original post

5 REPLIES 5
Reeza
Super User

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


 

ballardw
Super User

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.

tekish
Quartz | Level 8

Ballardw,

 

It works.

 

thanks,

 

Reeza
Super User

@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.

novinosrin
Tourmaline | Level 20

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

sas-innovate-2024.png

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.

 

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.

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
  • 5 replies
  • 1608 views
  • 3 likes
  • 4 in conversation