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

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16

Please try the intck function

 

if intck('month', start_date, end_date, 'continuous')<6 then newparameter=1;

 

 

Thanks,
Jag

View solution in original post

7 REPLIES 7
PeterClemmensen
Tourmaline | Level 20

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;
Patrick
Opal | Level 21

@PierreYvesILY 

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.

PierreYvesILY
Pyrite | Level 9

I always test the solutions proposed before sending an approval.

 

I just got my tests results and can now close the question.

Jagadishkatam
Amethyst | Level 16

Please try the intck function

 

if intck('month', start_date, end_date, 'continuous')<6 then newparameter=1;

 

 

Thanks,
Jag
PierreYvesILY
Pyrite | Level 9

I implemented this solution, which has been tested now on a range of 200000 cases without any pb.

 

Thanks!

ed_sas_member
Meteorite | Level 14

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;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 7 replies
  • 5294 views
  • 6 likes
  • 5 in conversation