<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Month between two dates in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Month-between-two-dates/m-p/707064#M217082</link>
    <description>Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt; thank you for your answer. But logically between 01FEB2021 and 31JAN2022 you have 12 month. Is there another way to calculate the correct difference?</description>
    <pubDate>Fri, 18 Dec 2020 20:04:05 GMT</pubDate>
    <dc:creator>aguilar_john</dc:creator>
    <dc:date>2020-12-18T20:04:05Z</dc:date>
    <item>
      <title>Month between two dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Month-between-two-dates/m-p/707056#M217076</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;
&lt;P&gt;it seems that the SAS intck function has a problem when calculating the difference between two dates within a month.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to calculate the month between 01FEB2021 and 31JAN2022, but even with the continous option the result is 11 month.&lt;/P&gt;
&lt;PRE&gt;data test;
	date=intck("month",'01FEB2021'd,'31JAN2022'd,'c');
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Any ideas how to solve this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Dec 2020 19:37:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Month-between-two-dates/m-p/707056#M217076</guid>
      <dc:creator>aguilar_john</dc:creator>
      <dc:date>2020-12-18T19:37:37Z</dc:date>
    </item>
    <item>
      <title>Re: Month between two dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Month-between-two-dates/m-p/707057#M217077</link>
      <description>&lt;P&gt;What do expect the answer to be?&lt;/P&gt;</description>
      <pubDate>Fri, 18 Dec 2020 19:48:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Month-between-two-dates/m-p/707057#M217077</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-12-18T19:48:57Z</dc:date>
    </item>
    <item>
      <title>Re: Month between two dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Month-between-two-dates/m-p/707058#M217078</link>
      <description>12&lt;BR /&gt;feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec,jan</description>
      <pubDate>Fri, 18 Dec 2020 19:52:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Month-between-two-dates/m-p/707058#M217078</guid>
      <dc:creator>aguilar_john</dc:creator>
      <dc:date>2020-12-18T19:52:03Z</dc:date>
    </item>
    <item>
      <title>Re: Month between two dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Month-between-two-dates/m-p/707060#M217080</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/154812"&gt;@aguilar_john&lt;/a&gt;&amp;nbsp; Please be aware your interval doesn't exceed 364 days or in other words doesn't complete a full 12 month period&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	date=intck("month",'01FEB2021'd,'01feb2022'd,'c');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;12th month elapses on 01feb2022&lt;/P&gt;
&lt;P&gt;Alternatively if you mean inclusive of start date then-&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;date=intck("month",'01FEB2021'd,'31JAN2022'd,'c')+1;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 18 Dec 2020 20:01:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Month-between-two-dates/m-p/707060#M217080</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-12-18T20:01:03Z</dc:date>
    </item>
    <item>
      <title>Re: Month between two dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Month-between-two-dates/m-p/707064#M217082</link>
      <description>Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt; thank you for your answer. But logically between 01FEB2021 and 31JAN2022 you have 12 month. Is there another way to calculate the correct difference?</description>
      <pubDate>Fri, 18 Dec 2020 20:04:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Month-between-two-dates/m-p/707064#M217082</guid>
      <dc:creator>aguilar_john</dc:creator>
      <dc:date>2020-12-18T20:04:05Z</dc:date>
    </item>
    <item>
      <title>Re: Month between two dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Month-between-two-dates/m-p/707068#M217084</link>
      <description>&lt;P&gt;The +1 at the end also came to mind, but since I have to do this calculation for great number of different dates, I am not sure if the +1 I would solve this case but show another case wrong. Any other ideas or more general solution?&lt;/P&gt;</description>
      <pubDate>Fri, 18 Dec 2020 20:22:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Month-between-two-dates/m-p/707068#M217084</guid>
      <dc:creator>aguilar_john</dc:creator>
      <dc:date>2020-12-18T20:22:48Z</dc:date>
    </item>
    <item>
      <title>Re: Month between two dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Month-between-two-dates/m-p/707074#M217086</link>
      <description>&lt;P&gt;Lets go to a very simple example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data test;&lt;BR /&gt;d1=intck("month",'31JAN2020'd,'01Feb2020'd);&lt;BR /&gt;d2=intck("month",'31JAN2020'd,'01Feb2020'd,'c');&lt;BR /&gt;d3=intck("month",'31JAN2020'd,'28Feb2020'd,'c');&lt;BR /&gt;d4=intck("month",'31JAN2020'd,'29Feb2020'd,'c');&lt;BR /&gt;d5=intck("month",'31JAN2020'd,'01Mar2020'd,'c');&lt;BR /&gt;run;&lt;/PRE&gt;
&lt;P&gt;D1 has a value of 1. Is that correct for your interpretation of month?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;D2 has a value of 0. How does that relate to your interpretation.&lt;/P&gt;
&lt;P&gt;D3 is 0 because it is not the equivalent of the end of the month yet.&lt;/P&gt;
&lt;P&gt;D4 is 1 because an entire "month" has now passed.&lt;/P&gt;
&lt;P&gt;D5 is still one, the result continues to be 1 until the end of March.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So in your calculation the month does not advance until the next actual first of the month is encountered, ie 01 Feb.&lt;/P&gt;
&lt;P&gt;You can see some of this in the related INTNX function advance a 01Feb date 11 months and see the result:&lt;/P&gt;
&lt;PRE&gt;data example;
  date = '01Feb2021'd;
  d2 = intnx('month',date,11,'b');
  d3 = intnx('month',date,11,'e');
  d4 = intnx('month',date,11,'s');
  format d: date9.;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Dec 2020 20:35:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Month-between-two-dates/m-p/707074#M217086</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-12-18T20:35:37Z</dc:date>
    </item>
    <item>
      <title>Re: Month between two dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Month-between-two-dates/m-p/707076#M217088</link>
      <description>&lt;P&gt;Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt; thank you for the answer. This however does not solve my problem. In your first example d3 d3=intck("month",'31JAN2020'd,'28Feb2020'd,'c'); I would also expect the value to be 1.&lt;BR /&gt;But it seems that there is no general way to show this with SAS.&lt;/P&gt;
&lt;PRE&gt;d2=intck("month",'31JAN2020'd,'01Feb2020'd,'c'); &lt;/PRE&gt;
&lt;P&gt;would not exist, cause for my purpose always the whole month for the enddate would be relevant.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Dec 2020 20:51:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Month-between-two-dates/m-p/707076#M217088</guid>
      <dc:creator>aguilar_john</dc:creator>
      <dc:date>2020-12-18T20:51:33Z</dc:date>
    </item>
    <item>
      <title>Re: Month between two dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Month-between-two-dates/m-p/707081#M217090</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/154812"&gt;@aguilar_john&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt; thank you for the answer. This however does not solve my problem. In your first example d3 d3=intck("month",'31JAN2020'd,'28Feb2020'd,'c'); I would also expect the value to be 1.&lt;BR /&gt;But it seems that there is no general way to show this with SAS.&lt;/P&gt;
&lt;PRE&gt;d2=intck("month",'31JAN2020'd,'01Feb2020'd,'c'); &lt;/PRE&gt;
&lt;P&gt;would not exist, cause for my purpose always the whole month for the enddate would be relevant.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;Are all of your actual dates first/ last of the month? Then maybe the 'C' option is not for you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm not really sure what your rules are. It may be that you could use a different interval like "weeks" and some arithmetic if the +1 to the month interval doesn't work. Or creative use of INTNX plus INTCK&lt;/P&gt;</description>
      <pubDate>Fri, 18 Dec 2020 21:12:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Month-between-two-dates/m-p/707081#M217090</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-12-18T21:12:57Z</dc:date>
    </item>
    <item>
      <title>Re: Month between two dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Month-between-two-dates/m-p/707114#M217099</link>
      <description>&lt;P&gt;The INTCK function just counts the number of month boundaries crossed between the 2 dates (except if you use the "continuous" method as the 4th argument).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So&amp;nbsp; intck('month','01feb20201d,'31jan2022'd) must be 11, because that is the number of boundaries crossed.&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;feb/mar&lt;/LI&gt;
&lt;LI&gt;mar/apr&lt;/LI&gt;
&lt;LI&gt;apr/may&lt;/LI&gt;
&lt;LI&gt;may/jun&lt;/LI&gt;
&lt;LI&gt;jun/jul&lt;/LI&gt;
&lt;LI&gt;jul/aug&lt;/LI&gt;
&lt;LI&gt;aug/sep&lt;/LI&gt;
&lt;LI&gt;sep/oct&lt;/LI&gt;
&lt;LI&gt;oct/nov&lt;/LI&gt;
&lt;LI&gt;nov/dec&lt;/LI&gt;
&lt;LI&gt;dec/jan&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Editted note: Sorry, didn't paste in my second example, which was more relevant.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the case of 'continuous', the first date establishes the month "boundary".&amp;nbsp; In your case, it's the number of 01mmm dates covered between the dates, which is the same as "discrete".&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try continuous starting with, say 10feb2021.&amp;nbsp; Then it's the number of 10mmm's encountered:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;10mar2021&lt;/LI&gt;
&lt;LI&gt;10apr2021&lt;/LI&gt;
&lt;LI&gt;....&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; 11. 10jan2022&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Of course, it's not quite as simple if the starting date is 29,30 or 31,because shorter months must be accommodated.&amp;nbsp; Effectively there must be a boundary identified in each month - either it's the day component of the first date, or if no such day exists for a given month, it's the normal discrete month boundary.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 19 Dec 2020 02:20:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Month-between-two-dates/m-p/707114#M217099</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-12-19T02:20:28Z</dc:date>
    </item>
    <item>
      <title>Re: Month between two dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Month-between-two-dates/m-p/707255#M217138</link>
      <description>&lt;P&gt;It was supposed&amp;nbsp; to be ,you didn't reach 01feb2020. If you want 12 ,just add 1 at end of date.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
	date=intck("month",'01FEB2021'd,'31JAN2022'd +1,'c');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 20 Dec 2020 12:59:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Month-between-two-dates/m-p/707255#M217138</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-12-20T12:59:15Z</dc:date>
    </item>
    <item>
      <title>Re: Month between two dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Month-between-two-dates/m-p/707677#M217310</link>
      <description>Thank you for the elaborate answer.</description>
      <pubDate>Tue, 22 Dec 2020 15:04:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Month-between-two-dates/m-p/707677#M217310</guid>
      <dc:creator>aguilar_john</dc:creator>
      <dc:date>2020-12-22T15:04:02Z</dc:date>
    </item>
    <item>
      <title>Re: Month between two dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Month-between-two-dates/m-p/707679#M217311</link>
      <description>Thank you for the answer, this approach was also mentioned by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;, but since I have to do this calculation for many different dates I am not sure if the +1 will always show the correct value for me.</description>
      <pubDate>Tue, 22 Dec 2020 15:06:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Month-between-two-dates/m-p/707679#M217311</guid>
      <dc:creator>aguilar_john</dc:creator>
      <dc:date>2020-12-22T15:06:00Z</dc:date>
    </item>
    <item>
      <title>Re: Month between two dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Month-between-two-dates/m-p/707700#M217323</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/154812"&gt;@aguilar_john&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thank you for the answer, this approach was also mentioned by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;, but since I have to do this calculation for many different dates I am not sure if the +1 will always show the correct value for me.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Then run an experiment and check.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
   do start='01JAN2020'd to '31JAN2020'd ;
      do end='01MAR2020'd to '31MAR2020'd ;
         d1=intnx('month',start,end,'c');
         d2=intnx('month',start,end+1,'c');
         if not (d1=d2) then output;
    end;
  end;
  format start end date9.;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 22 Dec 2020 16:26:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Month-between-two-dates/m-p/707700#M217323</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-12-22T16:26:57Z</dc:date>
    </item>
  </channel>
</rss>

