<?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: Creating Flags for Six Month Increments in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-Flags-for-Six-Month-Increments/m-p/720078#M223028</link>
    <description>I would advise against the usage of the term months here. You're using equally spaced intervals, but months are not equally spaced and they won't align with calendar months if you do any reporting at that level.</description>
    <pubDate>Thu, 18 Feb 2021 00:09:10 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2021-02-18T00:09:10Z</dc:date>
    <item>
      <title>Creating Flags for Six Month Increments</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-Flags-for-Six-Month-Increments/m-p/720068#M223022</link>
      <description>&lt;P&gt;I'm not sure if what I'm trying to do is possible but, any help would be greatly appreciated.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have several rows of data. What I would like to do is calculate the number of days between each date by ID &lt;BR /&gt;and create the following flags:&lt;/P&gt;
&lt;P&gt;le 180 days = 6 months &lt;BR /&gt;181 days to 360 days = 12 months&lt;BR /&gt;361 days to 540 days = 18 months &lt;BR /&gt;541 days to 720 days = 24 months &lt;BR /&gt;ge 721 days = gt two years&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, for ID 2 12/13/2016 - 03/14/2017 = 91 days, 03/14/2017-07/11/2017 = 120 so 120+90=210 therefore I should get&lt;BR /&gt;a flag then continue on. The sample data is below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data mydata;&lt;BR /&gt; input ID DATE:mmddyy10. ;&lt;BR /&gt; format  DATE mmddyy10.; &lt;BR /&gt; datalines;&lt;BR /&gt;1  07/31/2017&lt;BR /&gt;1  08/14/2017&lt;BR /&gt;1  08/15/2017&lt;BR /&gt;1  08/21/2017&lt;BR /&gt;1  09/08/2017&lt;BR /&gt;1  10/27/2017&lt;BR /&gt;1  01/03/2019&lt;BR /&gt;1  02/28/2019&lt;BR /&gt;1  03/01/2019&lt;BR /&gt;1  03/18/2019&lt;BR /&gt;2  12/13/2016&lt;BR /&gt;2  03/14/2017&lt;BR /&gt;2  07/11/2017&lt;BR /&gt;2  07/12/2017&lt;BR /&gt;2  08/22/2017&lt;BR /&gt;3  12/15/2017&lt;BR /&gt;4  10/25/2016&lt;BR /&gt;5  11/30/2016&lt;BR /&gt;5  11/30/2016&lt;BR /&gt;5  12/12/2016&lt;BR /&gt;5  12/21/2016&lt;BR /&gt;5  02/17/2017&lt;BR /&gt;5  03/24/2017&lt;BR /&gt;6  12/22/2020&lt;BR /&gt;7  03/26/2019&lt;BR /&gt;7  04/08/2019&lt;BR /&gt;8  01/27/2021&lt;BR /&gt;8  02/04/2021&lt;BR /&gt;9  07/12/2016&lt;BR /&gt;10 05/04/2018&lt;BR /&gt;10 05/25/2018&lt;BR /&gt;10 09/24/2019&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Feb 2021 23:02:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-Flags-for-Six-Month-Increments/m-p/720068#M223022</guid>
      <dc:creator>luvscandy27</dc:creator>
      <dc:date>2021-02-17T23:02:40Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Flags for Six Month Increments</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-Flags-for-Six-Month-Increments/m-p/720071#M223023</link>
      <description>&lt;P&gt;You can get the intervals this way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want;
   set mydata;
   by id;
   retain firstdate;
   if first.id then firstdate=date;
   interval = date-firstdate;
run;&lt;/PRE&gt;
&lt;P&gt;Personally I would use a custom format to assign a "flag" value based on the interval. That way when you decide to consider a different set of "flags" then you can use a different format.&lt;/P&gt;
&lt;P&gt;The format would look something like:&lt;/P&gt;
&lt;PRE&gt;proc format;
value flag
0- 180     = ' 6 months'
181 - 360  = '12 months'
361 - 540  = '18 months'
541 - 720  = '24 months'
721 - high = 'GT two years'
;
run;&lt;/PRE&gt;
&lt;P&gt;Assign the format to the interval as needed.&lt;/P&gt;
&lt;P&gt;Groups created by formats are honored&amp;nbsp; by reporting procedures like Report and Tabulate, most analysis procedures and most places in graphs.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Feb 2021 23:16:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-Flags-for-Six-Month-Increments/m-p/720071#M223023</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-02-17T23:16:36Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Flags for Six Month Increments</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-Flags-for-Six-Month-Increments/m-p/720078#M223028</link>
      <description>I would advise against the usage of the term months here. You're using equally spaced intervals, but months are not equally spaced and they won't align with calendar months if you do any reporting at that level.</description>
      <pubDate>Thu, 18 Feb 2021 00:09:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-Flags-for-Six-Month-Increments/m-p/720078#M223028</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-02-18T00:09:10Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Flags for Six Month Increments</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-Flags-for-Six-Month-Increments/m-p/720310#M223127</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;More to Rezza's point:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is a great example to use INTCK() with the CONTINUOUS option.&amp;nbsp; INTCK() should have the advantage that there will not be "discontinuities" in counting days/months based on leap years or for which month a count starts in.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
  value flag
    0 = ' 6 months'
    1 = '12 months'
    2 = '18 months'
    3 = '24 months'
    4 = 'GT two years'
;
run;

data want;
  if 0 then set have(keep=ID);
  retain firstdate;
    format firstdate mmddyy10.;

  do until (last.ID);
    set have;
      by ID;
    interval_months = intck('month6',firstdate,date,"continuous"); 
      format interval_months flag.;
      label interval_months="number of 6-month periods";
    if first.ID 
      then firstdate=date;
      else output;
  end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Feb 2021 20:01:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-Flags-for-Six-Month-Increments/m-p/720310#M223127</guid>
      <dc:creator>PhilC</dc:creator>
      <dc:date>2021-02-18T20:01:10Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Flags for Six Month Increments</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-Flags-for-Six-Month-Increments/m-p/720327#M223135</link>
      <description>lag function is another option</description>
      <pubDate>Thu, 18 Feb 2021 21:16:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-Flags-for-Six-Month-Increments/m-p/720327#M223135</guid>
      <dc:creator>Suzy_Cat</dc:creator>
      <dc:date>2021-02-18T21:16:22Z</dc:date>
    </item>
  </channel>
</rss>

