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

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register 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
  • 3828 views
  • 0 likes
  • 3 in conversation