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

Hi,

I have a table with date values. The dates in datetime20.0 format.

I would like to add 22 months to those value using an sql procedure.

What is the easiest way to do this?

Thank you for your help and time.


1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Use the INTNX() function.

SAS(R) 9.2 Language Reference: Dictionary, Fourth Edition


If you are using DATETIME20.0 format then you have DATETIME values instead of DATE values.  So use the DTMONTH interval instead of the MONTH interval.

data _null_;

  now=datetime();

  future = intnx('dtmonth',now,22-1,'S');

  format now future datetime22.;

  put (_all_) (=/);

run;

now=07NOV2013:15:23:08

future=07AUG2015:15:23:08



You can use the function call in SQL the same as you would in a DATA step, but you might need to give the result a variable name.

select mydate

     , intnx('dtmonth',MYDATE,22-1,'S') as future_date format=datetime22.

from mytable

View solution in original post

3 REPLIES 3
jakarman
Barite | Level 11

SAS(R) 9.3 Functions and CALL Routines: Reference (intnx and the related fucntions)
Be aware as this is a SAS function Performance will be the best wiht that for SAS-datasets.

When you are dealing with an external DBMS this can become challenging as date/time values are not standardized.

---->-- ja karman --<-----
Tom
Super User Tom
Super User

Use the INTNX() function.

SAS(R) 9.2 Language Reference: Dictionary, Fourth Edition


If you are using DATETIME20.0 format then you have DATETIME values instead of DATE values.  So use the DTMONTH interval instead of the MONTH interval.

data _null_;

  now=datetime();

  future = intnx('dtmonth',now,22-1,'S');

  format now future datetime22.;

  put (_all_) (=/);

run;

now=07NOV2013:15:23:08

future=07AUG2015:15:23:08



You can use the function call in SQL the same as you would in a DATA step, but you might need to give the result a variable name.

select mydate

     , intnx('dtmonth',MYDATE,22-1,'S') as future_date format=datetime22.

from mytable

cynthya
Calcite | Level 5

Thank you very much Tom.

This works perfectly.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 3450 views
  • 3 likes
  • 3 in conversation