Help using Base SAS procedures

Adding month to datetime20.0 value

Accepted Solution Solved
Reply
New Contributor
Posts: 4
Accepted Solution

Adding month to datetime20.0 value

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.



Accepted Solutions
Solution
‎11-07-2013 03:24 PM
Super User
Super User
Posts: 6,499

Re: Adding month to datetime20.0 value

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


All Replies
Valued Guide
Posts: 3,208

Re: Adding month to datetime20.0 value

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 --<-----
Solution
‎11-07-2013 03:24 PM
Super User
Super User
Posts: 6,499

Re: Adding month to datetime20.0 value

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

New Contributor
Posts: 4

Re: Adding month to datetime20.0 value

Thank you very much Tom.

This works perfectly.

☑ This topic is SOLVED.

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

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