<?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 read consecutive occurrence of counts in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-consecutive-occurrence-of-counts/m-p/709486#M218183</link>
    <description>the example you provided above is very good. I still want the outcome to look like this. which is having the first 2 consecutive 1's.&lt;BR /&gt;id value&lt;BR /&gt;&lt;BR /&gt;1 2 &lt;BR /&gt;&lt;BR /&gt;1 8 &lt;BR /&gt;&lt;BR /&gt;3 5 &lt;BR /&gt;&lt;BR /&gt;3 4</description>
    <pubDate>Tue, 05 Jan 2021 19:38:09 GMT</pubDate>
    <dc:creator>hjjijkkl</dc:creator>
    <dc:date>2021-01-05T19:38:09Z</dc:date>
    <item>
      <title>How to read consecutive occurrence of counts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-consecutive-occurrence-of-counts/m-p/709471#M218176</link>
      <description>&lt;P&gt;Hello;&lt;/P&gt;
&lt;P&gt;I have this kind of data&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data have;&lt;/P&gt;
&lt;P&gt;input id value count;&lt;/P&gt;
&lt;P&gt;record;&lt;/P&gt;
&lt;P&gt;1 2 1&lt;/P&gt;
&lt;P&gt;1 8 1&lt;/P&gt;
&lt;P&gt;1 12 0&lt;/P&gt;
&lt;P&gt;2 35 0&lt;/P&gt;
&lt;P&gt;2 15 0&lt;/P&gt;
&lt;P&gt;2 3 1&lt;/P&gt;
&lt;P&gt;3 11 0&lt;/P&gt;
&lt;P&gt;3 5 1&lt;/P&gt;
&lt;P&gt;3 4 1&lt;/P&gt;
&lt;P&gt;4 72 0&lt;/P&gt;
&lt;P&gt;4 8 1&lt;/P&gt;
&lt;P&gt;4 67 0&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want an the outcome table to look like this&lt;/P&gt;
&lt;P&gt;id value&lt;/P&gt;
&lt;P&gt;1 2&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1 8&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3 5&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3 4&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to count only two consecutive 1's in "count" variable.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jan 2021 18:30:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-read-consecutive-occurrence-of-counts/m-p/709471#M218176</guid>
      <dc:creator>hjjijkkl</dc:creator>
      <dc:date>2021-01-05T18:30:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to read consecutive occurrence of counts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-consecutive-occurrence-of-counts/m-p/709472#M218177</link>
      <description>&lt;P&gt;Here's a way.&amp;nbsp; Note that I'm taking your question literally.&amp;nbsp; If there are three consecutive occurrences, they will be ignored.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   totcount=0;
   do until (last.id);
      set have;
      by id;
      totcount + count;
   end;
   do until (last.id);
      set have;
      by id;
      if totcount=2 then output;
   end;
   drop totcount;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you really meant to say "2 or more" consecutive 1's, then change the comparison to read:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if totcount &amp;gt;= 2 then output;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This logic assumes that 0 and 1 are the only possible values for COUNT.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jan 2021 18:37:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-read-consecutive-occurrence-of-counts/m-p/709472#M218177</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2021-01-05T18:37:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to read consecutive occurrence of counts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-consecutive-occurrence-of-counts/m-p/709473#M218178</link>
      <description>&lt;P&gt;So what would you want if the data includes more than consecutive counts of 1 than 2? The first two, first and last, last two or something else? Or multiple sets of 2 (or more) consecutive?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your example was not very complete as to possible inputs, so you need to provide rules for processing something like the following &lt;STRONG&gt;or&lt;/STRONG&gt; state explicitly that the cases mentioned will never ever occur and not come back with questions when they do.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Such as:&lt;/P&gt;
&lt;P&gt;Data have;&lt;/P&gt;
&lt;P&gt;input id value count;&lt;/P&gt;
&lt;P&gt;record;&lt;/P&gt;
&lt;P&gt;1 2 1&lt;/P&gt;
&lt;P&gt;1 8 1&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;1 10 1&amp;nbsp;&lt;/STRONG&gt;&lt;/FONT&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Inserted to make additional consecutive as example.&lt;/P&gt;
&lt;P&gt;1 12 0&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;1 13 1&amp;nbsp;&lt;/STRONG&gt;&lt;/FONT&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Inserted to make additional consecutive as example.&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;1 18 1&amp;nbsp;&lt;/STRONG&gt;&lt;/FONT&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Inserted to make additional consecutive as example.&lt;/P&gt;
&lt;P&gt;2 35 0&lt;/P&gt;
&lt;P&gt;2 15 0&lt;/P&gt;
&lt;P&gt;2 3 1&lt;/P&gt;
&lt;P&gt;3 11 0&lt;/P&gt;
&lt;P&gt;3 5 1&lt;/P&gt;
&lt;P&gt;3 4 1&lt;/P&gt;
&lt;P&gt;4 72 0&lt;/P&gt;
&lt;P&gt;4 8 1&lt;/P&gt;
&lt;P&gt;4 67 0&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jan 2021 18:39:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-read-consecutive-occurrence-of-counts/m-p/709473#M218178</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-01-05T18:39:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to read consecutive occurrence of counts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-consecutive-occurrence-of-counts/m-p/709474#M218179</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
Data have;

input id value count;

cards;

1 2 1

1 8 1

1 12 0

2 35 0

2 15 0

2 3 1

3 11 0

3 5 1

3 4 1

4 72 0

4 8 1

4 67 0
;

data want;
 set have;
 by id count notsorted;
 if not(first.count and last.count);
 if count;
 drop count;
run;
 &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 05 Jan 2021 18:40:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-read-consecutive-occurrence-of-counts/m-p/709474#M218179</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2021-01-05T18:40:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to read consecutive occurrence of counts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-consecutive-occurrence-of-counts/m-p/709486#M218183</link>
      <description>the example you provided above is very good. I still want the outcome to look like this. which is having the first 2 consecutive 1's.&lt;BR /&gt;id value&lt;BR /&gt;&lt;BR /&gt;1 2 &lt;BR /&gt;&lt;BR /&gt;1 8 &lt;BR /&gt;&lt;BR /&gt;3 5 &lt;BR /&gt;&lt;BR /&gt;3 4</description>
      <pubDate>Tue, 05 Jan 2021 19:38:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-read-consecutive-occurrence-of-counts/m-p/709486#M218183</guid>
      <dc:creator>hjjijkkl</dc:creator>
      <dc:date>2021-01-05T19:38:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to read consecutive occurrence of counts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-consecutive-occurrence-of-counts/m-p/709488#M218184</link>
      <description>thank you.&lt;BR /&gt;If  there is more than 2 consecutive 1's but, if I want the outcome to have only the first 2 consecutive. how can I program that? &lt;BR /&gt;exmaple;&lt;BR /&gt;&lt;BR /&gt;Data have;&lt;BR /&gt;&lt;BR /&gt;input id value count;&lt;BR /&gt;&lt;BR /&gt;record;&lt;BR /&gt;&lt;BR /&gt;1 2 1&lt;BR /&gt;&lt;BR /&gt;1 8 1&lt;BR /&gt;&lt;BR /&gt;1 10 1       Inserted to make additional consecutive as example.&lt;BR /&gt;&lt;BR /&gt;1 12 0&lt;BR /&gt;&lt;BR /&gt;1 13 1       Inserted to make additional consecutive as example.&lt;BR /&gt;&lt;BR /&gt;1 18 1       Inserted to make additional consecutive as example.&lt;BR /&gt;&lt;BR /&gt;2 35 0&lt;BR /&gt;&lt;BR /&gt;2 15 0&lt;BR /&gt;&lt;BR /&gt;2 3 1&lt;BR /&gt;&lt;BR /&gt;3 11 0&lt;BR /&gt;&lt;BR /&gt;3 5 1&lt;BR /&gt;&lt;BR /&gt;3 4 1&lt;BR /&gt;&lt;BR /&gt;4 72 0&lt;BR /&gt;&lt;BR /&gt;4 8 1&lt;BR /&gt;&lt;BR /&gt;4 67 0&lt;BR /&gt;&lt;BR /&gt;I want an the outcome table to look like this&lt;BR /&gt;&lt;BR /&gt;id value&lt;BR /&gt;&lt;BR /&gt;1 2 &lt;BR /&gt;&lt;BR /&gt;1 8 &lt;BR /&gt;&lt;BR /&gt;3 5 &lt;BR /&gt;&lt;BR /&gt;3 4</description>
      <pubDate>Tue, 05 Jan 2021 19:52:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-read-consecutive-occurrence-of-counts/m-p/709488#M218184</guid>
      <dc:creator>hjjijkkl</dc:creator>
      <dc:date>2021-01-05T19:52:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to read consecutive occurrence of counts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-consecutive-occurrence-of-counts/m-p/709503#M218187</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/222563"&gt;@hjjijkkl&lt;/a&gt;&amp;nbsp; Oh you changed the requirement. Hmm&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data want;
 do _n_=1 by 1 until(last.count);
  set have;
  by id count notsorted;
  if first.id then do; _c1=0;_c=0;end;
  if first.count and count then _c1+1;
  if count then _c+1;
  else _c=0;
 end;
 do _n_=1 to _n_;
  set have;
  if count and _c1=1 and _c&amp;gt;=2 and _n_&amp;lt;=2 then output;
 end;
 drop _: count;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jan 2021 21:12:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-read-consecutive-occurrence-of-counts/m-p/709503#M218187</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2021-01-05T21:12:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to read consecutive occurrence of counts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-consecutive-occurrence-of-counts/m-p/709515#M218196</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/222563"&gt;@hjjijkkl&lt;/a&gt;&amp;nbsp; Oh you changed the requirement. Hmm&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Not so much a change of requirement as a clarification. I suspected the data OP presented might be too "clean" or simple and asked about clarification of requirement for more complex data. Seems like my question may have struck a chord or two with the full data in question.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Tue, 05 Jan 2021 21:49:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-read-consecutive-occurrence-of-counts/m-p/709515#M218196</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-01-05T21:49:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to read consecutive occurrence of counts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-consecutive-occurrence-of-counts/m-p/709603#M218254</link>
      <description>&lt;P&gt;Just for fun.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Data have;
input id value count;
cards;
1 2 1
1 8 1
1 10 1
1 12 0
1 13 1
1 18 1
2 35 0
2 15 0
2 3 1
3 11 0
3 5 1
3 4 1
4 72 0
4 8 1
4 67 0
;

data want;
 set have;
 by id count notsorted;
 if first.id then g=0;
 g+(first.count and count=1);
 if first.count then n=0;
 n+1;
 if not (first.count and last.count) and g=1 and n lt 3 and count;
 drop n g;
run;
 &lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Jan 2021 12:19:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-read-consecutive-occurrence-of-counts/m-p/709603#M218254</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-01-06T12:19:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to read consecutive occurrence of counts</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-read-consecutive-occurrence-of-counts/m-p/709622#M218260</link>
      <description>&lt;P&gt;My first answer was so pathetic, I need a mulligan.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set have;
   by id count notsorted;
   if first.id then found=0;
   retain found;
   if count=1;
   if first.count and last.count=0 and found=0;
   found = _n_;
   do _n_=_n_ to _n_ + 1;
      set have point=_n_;
      output;
   end;
   drop found;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Jan 2021 14:01:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-read-consecutive-occurrence-of-counts/m-p/709622#M218260</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2021-01-06T14:01:02Z</dc:date>
    </item>
  </channel>
</rss>

