I've used the following code to calculate months between two date variables, however, I feel like it's not as accurate as I'd like it to be...
data readms_dist2;
set readms_dist2;
Months_btwn_adms=intck('month', PRV_DC_DT, ADM_DT);
Weeks_btwn_adms=intck('week', PRV_DC_DT, ADM_DT);
Days_btwn_adms=intck('day', PRV_DC_DT, ADM_DT);
run;
From my understanidng, the intck month function just counts if the date has "crossed" into the next month -
So if had a PRV_DC_DT was january 1 2020 and the ADM_DT was january 30 2020, then the function would return 0.
but if PRV_DC_DT was january 30 2020 and ADM_DT was february 1 2020 then the function would return 1. This is correct right? Well, that's not very accurate in calculating how many months between two dates, so what's my best option?
Thanks!
IMHO, you would still need to test carefully with "C" and without "C"
Months_btwn_adms=intck('day30', PRV_DC_DT, ADM_DT,"c");
It seems quite likely you would need a 'C' for your custom interval too
Use 'C' for continuous
Months_btwn_adms=intck('month', PRV_DC_DT, ADM_DT,'c');
Thank you!
Yes, ok, I see that's what the other post did with the 'c' for continuous. This is good enough for my purposes 🙂
Makes sense. Is there a way to count by 30 day intervals? Can you use that as the fourth parameter?
Hi @accintron Not quite using the fourth argument. But you can use an Interval Multiplier to Create a Custom Interval.
For example day30 as the interval in your case
Months_btwn_adms=intck('day30', PRV_DC_DT, ADM_DT);
Ah ok! This is great. thanks so much. I'll check out both!
IMHO, you would still need to test carefully with "C" and without "C"
Months_btwn_adms=intck('day30', PRV_DC_DT, ADM_DT,"c");
It seems quite likely you would need a 'C' for your custom interval too
Ok, thank you for this advice. I will try out all three! 🙂
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Early bird rate extended! Save $200 when you sign up by March 31.
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.