DATA Step, Macro, Functions and more

Increment datetime format

Accepted Solution Solved
Reply
Contributor
Posts: 53
Accepted Solution

Increment datetime format

[ Edited ]

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


Accepted Solutions
Solution
‎04-14-2017 02:33 PM
Contributor
Posts: 53

Re: update datetime format

Ballardw,

 

It works.

 

thanks,

 

View solution in original post


All Replies
Super User
Posts: 19,782

Re: update datetime format

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


 

Super User
Posts: 11,343

Re: update datetime format

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.

Solution
‎04-14-2017 02:33 PM
Contributor
Posts: 53

Re: update datetime format

Ballardw,

 

It works.

 

thanks,

 

Super User
Posts: 19,782

Re: update datetime format

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

PROC Star
Posts: 283

Re: update datetime format

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

☑ This topic is solved.

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

Discussion stats
  • 5 replies
  • 190 views
  • 3 likes
  • 4 in conversation