dear SAS experts,
I need to programm the following difference between 2 dates and test if the difference in months is inferior to 6 months.
I can do this in days, but I can't get the right way to do this in Months (I cannot use standardized months or so, unfortunately)
if (DATE1 - DATE2) < 6 then NewParameter = 1;
how can I correct the (DATE1 - DATE2) expression to get the result in months?
Please try the intck function
if intck('month', start_date, end_date, 'continuous')<6 then newparameter=1;
The INTCK Function returns the number of interval boundaries between two dates
data _null_;
dt1='01jan2019'd;
dt2='16oct2019'd;
difmonths=intck('month', dt1, dt2);
put difmonths=;
run;
If what @PeterClemmensen posted is the solution for you then please mark it as solution so we know you've got your answer. Marking something as solution will also help others who search the forums later on to get answers to similar problems.
I always test the solutions proposed before sending an approval.
I just got my tests results and can now close the question.
Please try the intck function
if intck('month', start_date, end_date, 'continuous')<6 then newparameter=1;
I implemented this solution, which has been tested now on a range of 200000 cases without any pb.
Thanks!
Hi @PierreYvesILY ,
I suggest to use the intck() function.
It returns the number of interval boundaries of a given kind, like months.
Hope this help!
data want;
set have;
month_dif = intck('month',date1,date2);
run;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Lock in the best rate now before the price increases on April 1.
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.