title: Calculating number of months between 2 dates from SAS INTCK to Python
body: <p>I have the following SAS date logic to extract 'number of months' between 2 dates and appreciate if anyone can help me as how do I get this done in Python/Pandas dataframe</p>
  <pre><code>%let orig_val=10;
  %let mydate1=&quot;17JUL2019:00:00:00&quot;;
  %let mydate2=&quot;31DEC2019&quot;d;
  %let curmth=0;
  
  if &amp;orig_val in (4,10,12) then 
    num_mths =intck('month',datepart(&amp;mydate1), intnx('month', input(symget('&amp;mydate2'), date9.), -(&amp;curmth+1), &quot;end&quot;));
  </code></pre>
  <p>in my actual code, &amp;curmth value comes from a macro variable and it can be any number from 0 to 20 or more but &amp;mydate2 is always same 31Dec2019 date.</p>
  <p>Explanation of how the above above line of code will resolve for different 'curmth' and 'mydate1' values:</p>
  <p><em>When &amp;curmth=0 and &amp;mydate1=17JUL2019, for the 2nd date calculation, it subtracts &amp;mydate2-(&amp;curmth+1) =31Dec2019-(0+1)= 30Nov2019
  (note: 2nd date always resolves to the last day of that month as we are using 'end' parameter to do so) and resolves as below</em></p>
  <pre><code>** num_mths=intck('month','17JUL2019','30NOV2019') ***
  </code></pre>
  <p>and calculates number of months difference between 17jul2019 and 30Nov2019 as num_mnths which is 4:</p>
  <p>Similarly for other dates examples:</p>
  <p>when curmth=2 and mydate1=25MAR2019, it resolves as below and calculates the output num_mnths as 6:</p>
  <pre><code>** num_mths=intck('month','25MAR2019','30SEP2019') ***;
  </code></pre>
  <p>when curmth=5 and mydate1=14OCT2018,it resolves as below and calculates the output num_mnths as 8:</p>
  <pre><code>** num_mths=intck('month','14OCT2018','30JUN2019') ***;
  </code></pre>
  <p>when curmth=11 and mydate1=07NOV2017, it resolves as below and calculates the output num_mnths as 13:</p>
  <pre><code>** num_mths=intck('month','07NOV2017','31DEC2018') ***;
  </code></pre>
  <p>when curmth=12 and mydate1=16AUG2018, it resolves as below and calculates the output num_mnths as 3:</p>
  <pre><code>** num_mths=intck('month','16AUG2018','30NOV2018') ***;
  
  expected output examples
   1) when &amp;mydate1='18MAR2019:00:00:00' and &amp;curmth=0, then num_mths=8 
   2) when &amp;mydate1='15JUL2019:00:00:00' and &amp;curmth=1, then num_mths=3
   3) when &amp;mydate1='19FEB2019:00:00:00' and &amp;curmth=2, then num_mths=7
   4) when &amp;mydate1='11MAR2019:00:00:00' and &amp;curmth=3, then num_mths=5
   5) when &amp;mydate1='04SEP2018:00:00:00' and &amp;curmth=4, then num_mths=10
   6) when &amp;mydate1='14OCT2018:00:00:00' and &amp;curmth=5, then num_mths=8
   7) when &amp;mydate1='17MAY2018:00:00:00' and &amp;curmth=6, then num_mths=12
   8) when &amp;mydate1='18JUL2018:00:00:00' and &amp;curmth=6, then num_mths=9
  .....
  .....
  9) when &amp;mydate1='07NOV2017:00:00:00' and &amp;curmth=11, then num_mths=13
  10)when &amp;mydate1='16AUG2018:00:00:00' and &amp;curmth=12, then num_mths=3
  11)when &amp;mydate1='14JUN2018:00:00:00' and &amp;curmth=13, then num_mths=4
  12)when &amp;mydate1='23FEB2018:00:00:00' and &amp;curmth=14, then num_mths=7
  13)when &amp;mydate1='17APR2018:00:00:00' and &amp;curmth=15, then num_mths=4
  </code></pre>