<?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 identify/flag the first row of repetition(if repeats at least 3 times) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-identify-flag-the-first-row-of-repetition-if-repeats-at/m-p/889288#M351340</link>
    <description>Take a two-step approach:&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;by col1 col2 notsorted;&lt;BR /&gt;if first.col2 then count=1;&lt;BR /&gt;else count + 1;&lt;BR /&gt;if count=3;&lt;BR /&gt;found_at = _n_ - 2;&lt;BR /&gt;drop count;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;There are a variety of ways to combine WANT and HAVE to flag the proper observations (if you still need to do that).</description>
    <pubDate>Tue, 15 Aug 2023 06:21:10 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2023-08-15T06:21:10Z</dc:date>
    <item>
      <title>How to identify/flag the first row of repetition(if repeats at least 3 times)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-identify-flag-the-first-row-of-repetition-if-repeats-at/m-p/889281#M351336</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;i have a dataset as below&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;  data have;
        input col1 col2;
        datalines;
    1001 1.5
    1001 1
    1001 2.5
    1001 2.5
    1001 1.5&lt;BR /&gt;    1001 1.5&lt;BR /&gt;    1001 1.5&lt;BR /&gt;    1002 1.5
    1002 4.25
    1002 2.5
    1002 2.5
    1002 2.5&lt;BR /&gt;    1002 2.5&lt;BR /&gt;    1002 1.5&lt;BR /&gt;    1003 6.5
    1003 
    1003 1.5
    1003 1.5
    1003 2.5&lt;BR /&gt;    1003 2.5&lt;BR /&gt;    1003 2.5&lt;BR /&gt;    1003
    ;
    run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;from the above I have to filter out the rows that have repeats of values at least 3 times&lt;/P&gt;
&lt;P&gt;for the first category(1001), I need to flag the 5th row as that row got repeated with 1.5 with out any blank/any other value even though 1.5 is present on the first row(as it's not repetitive). similarly row no 10 should be flagged for 1002 as repeats are present at least 3 times there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;any help will be appriciated.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Aug 2023 05:42:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-identify-flag-the-first-row-of-repetition-if-repeats-at/m-p/889281#M351336</guid>
      <dc:creator>sahoositaram555</dc:creator>
      <dc:date>2023-08-15T05:42:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to identify/flag the first row of repetition(if repeats at least 3 times)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-identify-flag-the-first-row-of-repetition-if-repeats-at/m-p/889285#M351339</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
count = 0;
do until (last.col2);
  set have;
  by col1 col2 notsorted;
  count + 1;
end;
flag = (count ge 3);
do until (last.col2);
  set have;
  by col1 col2 notsorted;
  output;
  flag = 0;
end;
drop count;
run;
  &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Untested, posted from my tablet.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Aug 2023 06:13:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-identify-flag-the-first-row-of-repetition-if-repeats-at/m-p/889285#M351339</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-08-15T06:13:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to identify/flag the first row of repetition(if repeats at least 3 times)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-identify-flag-the-first-row-of-repetition-if-repeats-at/m-p/889288#M351340</link>
      <description>Take a two-step approach:&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;by col1 col2 notsorted;&lt;BR /&gt;if first.col2 then count=1;&lt;BR /&gt;else count + 1;&lt;BR /&gt;if count=3;&lt;BR /&gt;found_at = _n_ - 2;&lt;BR /&gt;drop count;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;There are a variety of ways to combine WANT and HAVE to flag the proper observations (if you still need to do that).</description>
      <pubDate>Tue, 15 Aug 2023 06:21:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-identify-flag-the-first-row-of-repetition-if-repeats-at/m-p/889288#M351340</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2023-08-15T06:21:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to identify/flag the first row of repetition(if repeats at least 3 times)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-identify-flag-the-first-row-of-repetition-if-repeats-at/m-p/889294#M351342</link>
      <description>&lt;P&gt;Thank you both. &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;it worked, but I realized this code is flagging every 1st occurrence if there are multiple triplicate recs present per category of COL1,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'd really appreciate if you can help with an idea- if the triplicate repeats found in col2 first time per category of col1, then not to consider all other triplicate repeats present afterwords(and not to consider missing triplicates if coming on the way).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sorry, I should have mentioned about this condition, apologies, should have been clearer earlier.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Aug 2023 06:48:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-identify-flag-the-first-row-of-repetition-if-repeats-at/m-p/889294#M351342</guid>
      <dc:creator>sahoositaram555</dc:creator>
      <dc:date>2023-08-15T06:48:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to identify/flag the first row of repetition(if repeats at least 3 times)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-identify-flag-the-first-row-of-repetition-if-repeats-at/m-p/889299#M351345</link>
      <description>&lt;P&gt;So we need another flag which keeps track of repeats found:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
retain flag2;
count = 0;
do until (last.col2);
  set have;
  by col1 col2 notsorted;
  if first.col1 then flag2 = 1;
  count + 1;
end;
flag = (count ge 3) and flag2;
if flag then flag2 = 0;
do until (last.col2);
  set have;
  by col1 col2 notsorted;
  output;
  flag = 0;
end;
drop count flag2;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 15 Aug 2023 07:00:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-identify-flag-the-first-row-of-repetition-if-repeats-at/m-p/889299#M351345</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-08-15T07:00:38Z</dc:date>
    </item>
  </channel>
</rss>

