<?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: Create Flags for Consecutive and Non Consecutive Flags in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-Flags-for-Consecutive-and-Non-Consecutive-Flags/m-p/745026#M233490</link>
    <description>&lt;P&gt;Run a DO loop:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
flag = 1;
cy = -1;
do until (last.id);
  set have;
  by id;
  if cycle gt cy + 1 then flag = 0;
  cy = cycle;
end;
keep id flag;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(untested, posted from my tablet)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to "remerge" the flag to the original dataset, add a second DO loop that reads the same group and OUTPUTs.&lt;/P&gt;</description>
    <pubDate>Tue, 01 Jun 2021 19:27:42 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2021-06-01T19:27:42Z</dc:date>
    <item>
      <title>Create Flags for Consecutive and Non Consecutive Flags</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-Flags-for-Consecutive-and-Non-Consecutive-Flags/m-p/745018#M233486</link>
      <description>&lt;P&gt;Hello All, &amp;nbsp;I want to flag ID's with consecutive flags as 1 and those without consecutive flags as 0. For example ID 1 is consecutive because it starts from cycle 1 to cycle 4 so I create a flag for ID 1 as 1. However for ID's with no consecutive cycle numbers like ID 2 (its starts from cycle 2 to cycle 5, missing cycle 1) and ID 3 also starts from cycle 8 missing cycles 1-7, &amp;nbsp;I flags these ID's as 0. Is there a way to go about this. Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class="language-sas"&gt;&lt;CODE&gt;Data have;
 input ID $1. Cycle;
Datalines;
1    1
1    1
1    2
1    3
1    4
2   3
2   4
2   5
3   8
3   8
;
run;&amp;nbsp;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Jun 2021 18:47:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-Flags-for-Consecutive-and-Non-Consecutive-Flags/m-p/745018#M233486</guid>
      <dc:creator>Paakay</dc:creator>
      <dc:date>2021-06-01T18:47:28Z</dc:date>
    </item>
    <item>
      <title>Re: Create Flags for Consecutive and Non Consecutive Flags</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-Flags-for-Consecutive-and-Non-Consecutive-Flags/m-p/745026#M233490</link>
      <description>&lt;P&gt;Run a DO loop:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
flag = 1;
cy = -1;
do until (last.id);
  set have;
  by id;
  if cycle gt cy + 1 then flag = 0;
  cy = cycle;
end;
keep id flag;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(untested, posted from my tablet)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to "remerge" the flag to the original dataset, add a second DO loop that reads the same group and OUTPUTs.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Jun 2021 19:27:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-Flags-for-Consecutive-and-Non-Consecutive-Flags/m-p/745026#M233490</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-06-01T19:27:42Z</dc:date>
    </item>
  </channel>
</rss>

