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

I'm trying to get to a more precise number of months between 2 dates than given by the INTCK function.

For example: INTCK('MONTH','15MAR2018'd,11MAR2019'd) returns 12 even though the difference is less than 12 month (by 4 days).

Is there a way I could return only the number of pull months between 2 dates? Or return a decimal representation of the number of months (11.93) between 2 dates?  Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

It's probably most accurate to compute number of days:

 

n_days = '11MAR2019'd - '15MAR2018'd;

 

Then you can convert that using any formula that you want, such as:

 

n_months = n_days / 30.25;

 

or

 

n_months = n_days / 365.25 * 12;

View solution in original post

2 REPLIES 2
Astounding
PROC Star

It's probably most accurate to compute number of days:

 

n_days = '11MAR2019'd - '15MAR2018'd;

 

Then you can convert that using any formula that you want, such as:

 

n_months = n_days / 30.25;

 

or

 

n_months = n_days / 365.25 * 12;

LawrenceHW
Quartz | Level 8

Try using the 'C' modifier to the INTCK function:

 

data test;
  x=INTCK('MONTH','15MAR2018'd,'11MAR2019'd);
  y=INTCK('MONTH','15MAR2018'd,'11MAR2019'd,'C');
run;

This will give Y=11 which is the number of whole months  between the 2 dates.

 

Cheers,

Lawrence

Catch up on SAS Innovate 2026

Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.

Explore Now →
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 4525 views
  • 0 likes
  • 3 in conversation