<?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 Find consecutive values count of NOT DONE in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Find-consecutive-values-count-of-NOT-DONE/m-p/741648#M231857</link>
    <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you please help me on how to find consecutive values count of NOT DONE? I have one dataset as below.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data check;&lt;BR /&gt;infile datalines missover;&lt;BR /&gt;input subject $3. visitn avalc $10. ;&lt;BR /&gt;datalines;&lt;BR /&gt;101 1 NOT DONE&lt;BR /&gt;101 2 DONE&lt;BR /&gt;101 3 NOT DONE&lt;BR /&gt;101 4 DONE&lt;BR /&gt;101 5 NOT DONE&lt;BR /&gt;101 6 NOT DONE&lt;BR /&gt;101 7 NOT DONE&lt;BR /&gt;101 8 DONE&lt;BR /&gt;101 9 NOT DONE&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to find how many records have consecutive NOT DONE for visits.From above data , i am expecting final count as 3 as NOT DONE occured on each consecutive visit 5,6 and 7.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
    <pubDate>Sat, 15 May 2021 15:03:13 GMT</pubDate>
    <dc:creator>draroda</dc:creator>
    <dc:date>2021-05-15T15:03:13Z</dc:date>
    <item>
      <title>Find consecutive values count of NOT DONE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-consecutive-values-count-of-NOT-DONE/m-p/741648#M231857</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you please help me on how to find consecutive values count of NOT DONE? I have one dataset as below.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data check;&lt;BR /&gt;infile datalines missover;&lt;BR /&gt;input subject $3. visitn avalc $10. ;&lt;BR /&gt;datalines;&lt;BR /&gt;101 1 NOT DONE&lt;BR /&gt;101 2 DONE&lt;BR /&gt;101 3 NOT DONE&lt;BR /&gt;101 4 DONE&lt;BR /&gt;101 5 NOT DONE&lt;BR /&gt;101 6 NOT DONE&lt;BR /&gt;101 7 NOT DONE&lt;BR /&gt;101 8 DONE&lt;BR /&gt;101 9 NOT DONE&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to find how many records have consecutive NOT DONE for visits.From above data , i am expecting final count as 3 as NOT DONE occured on each consecutive visit 5,6 and 7.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Sat, 15 May 2021 15:03:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-consecutive-values-count-of-NOT-DONE/m-p/741648#M231857</guid>
      <dc:creator>draroda</dc:creator>
      <dc:date>2021-05-15T15:03:13Z</dc:date>
    </item>
    <item>
      <title>Re: Find consecutive values count of NOT DONE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-consecutive-values-count-of-NOT-DONE/m-p/741649#M231858</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/44091"&gt;@draroda&lt;/a&gt;&amp;nbsp; The sage&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp; answered a similar question explaining the use case of "NOT SORTED" option in BY GROUP processing so beautifully. I recommend reading his posts. So-&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data check;
infile datalines missover;
input subject $3. visitn avalc $10. ;
datalines;
101 1 NOT DONE
101 2 DONE
101 3 NOT DONE
101 4 DONE
101 5 NOT DONE
101 6 NOT DONE
101 7 NOT DONE
101 8 DONE
101 9 NOT DONE
;

data want;
 do until(last.avalc);
  set check;
  by subject avalc notsorted;
  consecutive=sum(consecutive,1);
 end;
 do until(last.avalc);
  set check;
  by subject avalc notsorted;
  if consecutive&amp;gt;1 then output;
 end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Btw, I am not quite all that good in explaining besides the fact I am the laziest person on earth however by all means I recommnend reading posts by group of marvels -Sir&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp; etc. to gain speed&lt;/P&gt;</description>
      <pubDate>Sat, 15 May 2021 15:28:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-consecutive-values-count-of-NOT-DONE/m-p/741649#M231858</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2021-05-15T15:28:19Z</dc:date>
    </item>
    <item>
      <title>Re: Find consecutive values count of NOT DONE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-consecutive-values-count-of-NOT-DONE/m-p/741660#M231862</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set check;
by subject visitn; /* visitn purely to force correct order */
retain count _count;
if first.subject
then do;
  count = 0;
  _count = 0;
end;
if avalc = "DONE"
then do;
  count = max(count,_count);
  _count = 0;
end;
else _count + 1;
if last.subject;
keep subject count;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Untested, posted from my tablet.&lt;/P&gt;</description>
      <pubDate>Sat, 15 May 2021 19:05:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-consecutive-values-count-of-NOT-DONE/m-p/741660#M231862</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-05-15T19:05:19Z</dc:date>
    </item>
  </channel>
</rss>

