<?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: Loops? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Loops/m-p/46827#M12499</link>
    <description>Doc already suggested code that will do what you asked, but do you really want to stop processing for all groups when two 25s are found?  Or do you only want to not process any more of that group's records?&lt;BR /&gt;
&lt;BR /&gt;
If it is the latter, I'd suggest the following:&lt;BR /&gt;
&lt;BR /&gt;
DATA want;&lt;BR /&gt;
  SET have;&lt;BR /&gt;
  BY a;&lt;BR /&gt;
  if first.a then flag=0;&lt;BR /&gt;
  IF INDEX(b,'25') GT 0 THEN flag+1;&lt;BR /&gt;
  if flag lt 2 then output;&lt;BR /&gt;
RUN;</description>
    <pubDate>Sat, 10 Jul 2010 20:15:33 GMT</pubDate>
    <dc:creator>art297</dc:creator>
    <dc:date>2010-07-10T20:15:33Z</dc:date>
    <item>
      <title>Loops?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Loops/m-p/46825#M12497</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
How can I write a program that will look for "25" in column B below and stop at the second "25" for the same group in column A? I have been using the index feature to account for the double entries in column B but am at a loss on how to proceed in this case.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
A	B&lt;BR /&gt;
1	25&lt;BR /&gt;
1	30&lt;BR /&gt;
1	36&lt;BR /&gt;
2	25, 52&lt;BR /&gt;
2	40&lt;BR /&gt;
2	25&lt;BR /&gt;
&lt;BR /&gt;
Desired output:&lt;BR /&gt;
&lt;BR /&gt;
A	B&lt;BR /&gt;
1	25&lt;BR /&gt;
1	30&lt;BR /&gt;
1	36&lt;BR /&gt;
2	25, 52&lt;BR /&gt;
2	40</description>
      <pubDate>Fri, 09 Jul 2010 21:02:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Loops/m-p/46825#M12497</guid>
      <dc:creator>spg</dc:creator>
      <dc:date>2010-07-09T21:02:25Z</dc:date>
    </item>
    <item>
      <title>Re: Loops?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Loops/m-p/46826#M12498</link>
      <description>You will need to set up an indicator flag using a RETAIN statement.  You would set the indicator to 0 (off) for the first row in A and set it to 1 (on) for the first occurrence of 25.  If you find another 25, use the STOP command to terminate building the output data set.&lt;BR /&gt;
&lt;BR /&gt;
Read about RETAIN and BY-Group processing in the reference manual to understand how these things work together.&lt;BR /&gt;
&lt;BR /&gt;
Something like this should work (untested code):&lt;BR /&gt;
&lt;BR /&gt;
DATA new;&lt;BR /&gt;
SET old;&lt;BR /&gt;
BY a;&lt;BR /&gt;
RETAIN flag;&lt;BR /&gt;
IF first.a THEN flag=0;&lt;BR /&gt;
IF INDEX(b,'25') GT 0 THEN DO;&lt;BR /&gt;
  IF flag=1 THEN STOP;&lt;BR /&gt;
  flag=1;&lt;BR /&gt;
  END;&lt;BR /&gt;
RUN;</description>
      <pubDate>Fri, 09 Jul 2010 21:50:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Loops/m-p/46826#M12498</guid>
      <dc:creator>Doc_Duke</dc:creator>
      <dc:date>2010-07-09T21:50:18Z</dc:date>
    </item>
    <item>
      <title>Re: Loops?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Loops/m-p/46827#M12499</link>
      <description>Doc already suggested code that will do what you asked, but do you really want to stop processing for all groups when two 25s are found?  Or do you only want to not process any more of that group's records?&lt;BR /&gt;
&lt;BR /&gt;
If it is the latter, I'd suggest the following:&lt;BR /&gt;
&lt;BR /&gt;
DATA want;&lt;BR /&gt;
  SET have;&lt;BR /&gt;
  BY a;&lt;BR /&gt;
  if first.a then flag=0;&lt;BR /&gt;
  IF INDEX(b,'25') GT 0 THEN flag+1;&lt;BR /&gt;
  if flag lt 2 then output;&lt;BR /&gt;
RUN;</description>
      <pubDate>Sat, 10 Jul 2010 20:15:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Loops/m-p/46827#M12499</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2010-07-10T20:15:33Z</dc:date>
    </item>
    <item>
      <title>Re: Loops?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Loops/m-p/46828#M12500</link>
      <description>You are right Art297. This is exactly what I wanted. I should've been more clear.&lt;BR /&gt;
Anyway, thanks Doc! Thanks Art297! This was super helpful &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Mon, 12 Jul 2010 00:19:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Loops/m-p/46828#M12500</guid>
      <dc:creator>spg</dc:creator>
      <dc:date>2010-07-12T00:19:40Z</dc:date>
    </item>
  </channel>
</rss>

