<?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 Classic DoW loop flagging first variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Classic-DoW-loop-flagging-first-variable/m-p/292534#M311743</link>
    <description>&lt;P&gt;Hi SASCommunity - I have a set of participants and a set of dates that are divided into active(active=1) and postactive(active=0) periods. I'd like to flag the first date of each active period for each partipant.&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, in the following dataset I would like to have a FLAG variable as follows (forgive me if syntaxical error here - I'm a NEWBY to SAS):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data participantperiods;&lt;/P&gt;&lt;P&gt;input participants dates active FLAG;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;1 &amp;nbsp;date1 &amp;nbsp;1 &amp;nbsp;1&lt;/P&gt;&lt;P&gt;1 &amp;nbsp;date2 &amp;nbsp;1 &amp;nbsp;0&lt;/P&gt;&lt;P&gt;1 &amp;nbsp;date3 &amp;nbsp;0 &amp;nbsp;0&lt;/P&gt;&lt;P&gt;2 &amp;nbsp;date4 &amp;nbsp;1 &amp;nbsp;1&lt;/P&gt;&lt;P&gt;2 &amp;nbsp;date5 &amp;nbsp;1 &amp;nbsp;0&lt;/P&gt;&lt;P&gt;2 &amp;nbsp;date6 &amp;nbsp;1 &amp;nbsp;0&lt;/P&gt;&lt;P&gt;2 &amp;nbsp;date7 &amp;nbsp;0 &amp;nbsp;0&lt;/P&gt;&lt;P&gt;2 &amp;nbsp;date8 &amp;nbsp;0 &amp;nbsp;0;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like this to be in the form of a classic 2xDoW loop. This is what I have developed so far, but it is overflagging unfortunately:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data WANT;
     do until (last.PARTICIPANT);
          set HAVE;
          by PARTICIPANT;
          if first.PARTICIPANT then FIRSTFLAG=1;
     end;
     do until (last.PARTICIPANT);
          set HAVE;
          by PARTICIPANT;
     output;
     end;

     do until (last.PARTICIPANT);
          set HAVE;
          by PARTICIPANT;
          if FIRSTFLAG=1 and ACTIVE=1 then FIRSTACTIVEFLAG=1;
     end;

     do until (last.case_no);
          set Encountersbydayvendor4;
          by case_no;
          output;
     end;
run;&lt;/PRE&gt;</description>
    <pubDate>Thu, 18 Aug 2016 19:22:32 GMT</pubDate>
    <dc:creator>dweissner</dc:creator>
    <dc:date>2016-08-18T19:22:32Z</dc:date>
    <item>
      <title>Classic DoW loop flagging first variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Classic-DoW-loop-flagging-first-variable/m-p/292534#M311743</link>
      <description>&lt;P&gt;Hi SASCommunity - I have a set of participants and a set of dates that are divided into active(active=1) and postactive(active=0) periods. I'd like to flag the first date of each active period for each partipant.&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, in the following dataset I would like to have a FLAG variable as follows (forgive me if syntaxical error here - I'm a NEWBY to SAS):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data participantperiods;&lt;/P&gt;&lt;P&gt;input participants dates active FLAG;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;1 &amp;nbsp;date1 &amp;nbsp;1 &amp;nbsp;1&lt;/P&gt;&lt;P&gt;1 &amp;nbsp;date2 &amp;nbsp;1 &amp;nbsp;0&lt;/P&gt;&lt;P&gt;1 &amp;nbsp;date3 &amp;nbsp;0 &amp;nbsp;0&lt;/P&gt;&lt;P&gt;2 &amp;nbsp;date4 &amp;nbsp;1 &amp;nbsp;1&lt;/P&gt;&lt;P&gt;2 &amp;nbsp;date5 &amp;nbsp;1 &amp;nbsp;0&lt;/P&gt;&lt;P&gt;2 &amp;nbsp;date6 &amp;nbsp;1 &amp;nbsp;0&lt;/P&gt;&lt;P&gt;2 &amp;nbsp;date7 &amp;nbsp;0 &amp;nbsp;0&lt;/P&gt;&lt;P&gt;2 &amp;nbsp;date8 &amp;nbsp;0 &amp;nbsp;0;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like this to be in the form of a classic 2xDoW loop. This is what I have developed so far, but it is overflagging unfortunately:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data WANT;
     do until (last.PARTICIPANT);
          set HAVE;
          by PARTICIPANT;
          if first.PARTICIPANT then FIRSTFLAG=1;
     end;
     do until (last.PARTICIPANT);
          set HAVE;
          by PARTICIPANT;
     output;
     end;

     do until (last.PARTICIPANT);
          set HAVE;
          by PARTICIPANT;
          if FIRSTFLAG=1 and ACTIVE=1 then FIRSTACTIVEFLAG=1;
     end;

     do until (last.case_no);
          set Encountersbydayvendor4;
          by case_no;
          output;
     end;
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 18 Aug 2016 19:22:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Classic-DoW-loop-flagging-first-variable/m-p/292534#M311743</guid>
      <dc:creator>dweissner</dc:creator>
      <dc:date>2016-08-18T19:22:32Z</dc:date>
    </item>
    <item>
      <title>Re: Classic DoW loop flagging first variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Classic-DoW-loop-flagging-first-variable/m-p/292543#M311744</link>
      <description>&lt;P&gt;It appears as if the data is sorted by participants and descending active. If that is the case then this should work:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set participantperiods;
   by participants descending active;
   if first.participants and first.active and active=1 then flag=1;
   else flag=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;if not then sort by participants descending active and date may get what you are looking for.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Aug 2016 19:42:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Classic-DoW-loop-flagging-first-variable/m-p/292543#M311744</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-08-18T19:42:01Z</dc:date>
    </item>
  </channel>
</rss>

