<?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: How to determine if a month falls b/w two dates? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-determine-if-a-month-falls-b-w-two-dates/m-p/476912#M122761</link>
    <description>&lt;P&gt;Hi --,&lt;/P&gt;
&lt;P&gt;This solution works very well! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you so much!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;MK&lt;/P&gt;</description>
    <pubDate>Tue, 10 Jul 2018 19:12:40 GMT</pubDate>
    <dc:creator>MiraKr_</dc:creator>
    <dc:date>2018-07-10T19:12:40Z</dc:date>
    <item>
      <title>How to determine if a month falls b/w two dates?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-determine-if-a-month-falls-b-w-two-dates/m-p/476892#M122750</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I am trying the determine participation by month. Each patient has as a start and an end date in the dataset. I would like to check if the patient was present in Jan, Feb, Mar,...Dec. At the end, I need variables for Jan--Dec with values of 0/1 for each patient. The study spans b/w&amp;nbsp;2015-05-21 --- 2017-07-29.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to avoid writing a long code that looks like this:&lt;/P&gt;
&lt;P&gt;if STARTDT le ('01JAN2016'd) le ENDDT then January=1;&lt;BR /&gt; else if STARTDT le ('02JAN2016'd) le ENDDT then January=1;&lt;BR /&gt; ....&lt;BR /&gt; else if STARTDT le ('31JAN2016'd) le ENDDT then January=1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your insights regarding a more efficient way to do this!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;MK&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jul 2018 18:07:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-determine-if-a-month-falls-b-w-two-dates/m-p/476892#M122750</guid>
      <dc:creator>MiraKr_</dc:creator>
      <dc:date>2018-07-10T18:07:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine if a month falls b/w two dates?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-determine-if-a-month-falls-b-w-two-dates/m-p/476894#M122751</link>
      <description>&lt;P&gt;Let's start with the planning first.&amp;nbsp; Your study spans over two years.&amp;nbsp; Do&amp;nbsp; you really want January=1 to indicate any January, so you can't tell where it's January 2016 or January 2017 or both?&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jul 2018 18:15:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-determine-if-a-month-falls-b-w-two-dates/m-p/476894#M122751</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-07-10T18:15:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine if a month falls b/w two dates?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-determine-if-a-month-falls-b-w-two-dates/m-p/476896#M122752</link>
      <description>&lt;P&gt;The year is not important. So,&amp;nbsp; January=1 is any January.&amp;nbsp; Also, If a patient was present in Jan 2016 and Jan 2017, January=1.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you,&lt;/P&gt;
&lt;P&gt;Mira&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jul 2018 18:21:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-determine-if-a-month-falls-b-w-two-dates/m-p/476896#M122752</guid>
      <dc:creator>MiraKr_</dc:creator>
      <dc:date>2018-07-10T18:21:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine if a month falls b/w two dates?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-determine-if-a-month-falls-b-w-two-dates/m-p/476903#M122756</link>
      <description>&lt;P&gt;OK, here's a reasonable way to proceed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;array flags {12} January February March April May June July August September October November December;&lt;/P&gt;
&lt;P&gt;n_months = intck('month', startdt, enddt);&lt;/P&gt;
&lt;P&gt;starting_month = month(startdt);&lt;/P&gt;
&lt;P&gt;do k=0&amp;nbsp;to&amp;nbsp;min(11, n_months);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; mm = starting_month + k;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; if mm &amp;gt; 12 then mm = mm&amp;nbsp;- 12;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; flags{mm} = 1;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's untested, but looks about right.&amp;nbsp; See what you get.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jul 2018 18:40:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-determine-if-a-month-falls-b-w-two-dates/m-p/476903#M122756</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-07-10T18:40:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine if a month falls b/w two dates?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-determine-if-a-month-falls-b-w-two-dates/m-p/476912#M122761</link>
      <description>&lt;P&gt;Hi --,&lt;/P&gt;
&lt;P&gt;This solution works very well! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you so much!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;MK&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jul 2018 19:12:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-determine-if-a-month-falls-b-w-two-dates/m-p/476912#M122761</guid>
      <dc:creator>MiraKr_</dc:creator>
      <dc:date>2018-07-10T19:12:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine if a month falls b/w two dates?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-determine-if-a-month-falls-b-w-two-dates/m-p/476917#M122763</link>
      <description>&lt;P&gt;Astounding, would you mind to add some comments to this part of your code to help me understand what these statements do:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;do k=0 to min(11, n_months);&lt;/P&gt;
&lt;P&gt;mm = starting_month + k;&lt;/P&gt;
&lt;P&gt;if mm &amp;gt; 12 then mm = mm - 12;&lt;/P&gt;
&lt;P&gt;flags{mm} = 1;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I understand the rest of the code.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Many thanks!&lt;/P&gt;
&lt;P&gt;MK&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jul 2018 19:35:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-determine-if-a-month-falls-b-w-two-dates/m-p/476917#M122763</guid>
      <dc:creator>MiraKr_</dc:creator>
      <dc:date>2018-07-10T19:35:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine if a month falls b/w two dates?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-determine-if-a-month-falls-b-w-two-dates/m-p/476928#M122766</link>
      <description>&lt;P&gt;Working backwards.....&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;flags{mm}=1;&lt;/P&gt;
&lt;P&gt;Take one of the 12 variables stored in the array named FLAGS, and set its value to 1.&amp;nbsp; Which variable?&amp;nbsp; It depends on the value of mm, which had better range from 1 to 12 since the array contains 12 elements.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if mm &amp;gt; 12 then mm = mm - 12;&lt;/P&gt;
&lt;P&gt;Since mm is to be used to determine which of the 12 variables gets set to 1, its value needs to range from 1 to 12.&amp;nbsp; If it exceeds 12, instead of looking for month 13, subtract 12 so we're only looking for month 1 instead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;mm = starting_month + k;&lt;/P&gt;
&lt;P&gt;Which month are we looking for?&amp;nbsp; Remember, starting_month is the month (1 thru 12) of STARTDT.&amp;nbsp; So begin at that month (k=0, so mm=starting_month).&amp;nbsp; As the loop continues, k increases.&amp;nbsp; So each time through the loop, look for the next highest month.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;min(11, n_months)&lt;/P&gt;
&lt;P&gt;There's no need to cycle through any more than 12 months.&amp;nbsp; After 12 times, all 12 flags will be 1.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jul 2018 20:12:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-determine-if-a-month-falls-b-w-two-dates/m-p/476928#M122766</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-07-10T20:12:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine if a month falls b/w two dates?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-determine-if-a-month-falls-b-w-two-dates/m-p/476939#M122767</link>
      <description>&lt;P&gt;To test if two intervals S1 to E2 and S2 to E2 overlap you need to test&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;s1 &amp;lt;= e2 and e1 &amp;gt;= s2&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To test all 12 months you just need to test 12 months starting with the month that STARTDT is in.&lt;/P&gt;
&lt;P&gt;Let's make some test data.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
  input startdt enddt ;
  format startdt enddt yymmdd10. ;
  informat startdt enddt yymmdd. ;
cards;
20180101 20180130
20160229 20170301
20160305 20160402
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now let's create the flags.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  set have ;
  array months jan feb mar apr may jun jul aug sep oct nov dec ;
  do i=0 to 11 ;
    months(1+mod(month(startdt)+i-1,12))
       = startdt &amp;lt;= intnx('month',startdt,i,'e')  and enddt &amp;gt;= intnx('month',startdt,i,'b')
    ;
  end;
  drop i;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 597px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/21702i7D55647AD1504FA9/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jul 2018 20:56:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-determine-if-a-month-falls-b-w-two-dates/m-p/476939#M122767</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-07-10T20:56:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine if a month falls b/w two dates?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-determine-if-a-month-falls-b-w-two-dates/m-p/477111#M122823</link>
      <description>&lt;P&gt;Thank you, Tom. This solution works very well and produces identical results to Astounding's code and also flags the 0s (instead of assigning missing).&amp;nbsp; Would you mind to explain what this part of the code does:&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt; months&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;+&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;mod&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;month&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;startdt&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;+&lt;/SPAN&gt;i&lt;SPAN class="token operator"&gt;-&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;12&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thank you,&lt;/P&gt;
&lt;P&gt;MK&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jul 2018 14:58:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-determine-if-a-month-falls-b-w-two-dates/m-p/477111#M122823</guid>
      <dc:creator>MiraKr_</dc:creator>
      <dc:date>2018-07-11T14:58:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine if a month falls b/w two dates?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-determine-if-a-month-falls-b-w-two-dates/m-p/477112#M122824</link>
      <description>&lt;P&gt;Thank you for the explanation, Astounding!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jul 2018 15:01:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-determine-if-a-month-falls-b-w-two-dates/m-p/477112#M122824</guid>
      <dc:creator>MiraKr_</dc:creator>
      <dc:date>2018-07-11T15:01:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine if a month falls b/w two dates?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-determine-if-a-month-falls-b-w-two-dates/m-p/477113#M122825</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12283"&gt;@MiraKr_&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you, Tom. This solution works very well and produces identical results to Astounding's code and also flags the 0s (instead of assigning missing).&amp;nbsp; Would you mind to explain what this part of the code does:&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt; months&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;+&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;mod&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;month&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;startdt&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;+&lt;/SPAN&gt;i&lt;SPAN class="token operator"&gt;-&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;12&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thank you,&lt;/P&gt;
&lt;P&gt;MK&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It is the left part of an assignment statement that continues on the following lines.&lt;/P&gt;
&lt;P&gt;Basically is indexing into the proper entry in the array named MONTHS for the current iteration of the DO loop.&lt;/P&gt;
&lt;P&gt;You can work out the math yourself to see how it gets to the proper index number.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jul 2018 15:05:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-determine-if-a-month-falls-b-w-two-dates/m-p/477113#M122825</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-07-11T15:05:20Z</dc:date>
    </item>
  </channel>
</rss>

