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

Hi,

 

Please can someone help me with the code to find the months difference between the current month (i.e. it would be August 2020, but would reflect the current month whenever the code was run) and the "RUN_DATE" variable (which is Numeric and has a DATE9. format)?

 

An example of records for RUN_DATE is 31MAY2012.

 

So it would be :

Months_difference = month(today's date) - month(RUN_DATE)

 

So for the 31MAY2012 example, Months_difference would equal 99 (August 2020 - May 2012).

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

SAS provides a few functions to deal with date and time intervals, namely INTNX (calculates a target from a start and a difference value) and INTCK (calculates a difference between two date or time values).

So you should try this:

Months_difference = intck('month',run_date,today());

Study the documentation about the method modifier.

View solution in original post

1 REPLY 1
Kurt_Bremser
Super User

SAS provides a few functions to deal with date and time intervals, namely INTNX (calculates a target from a start and a difference value) and INTCK (calculates a difference between two date or time values).

So you should try this:

Months_difference = intck('month',run_date,today());

Study the documentation about the method modifier.

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

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 1 reply
  • 803 views
  • 0 likes
  • 2 in conversation