<?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: Infinite Loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Infinite-Loop/m-p/38849#M7840</link>
    <description>the line "ELSE IF FIRST.A AND B='N' THEN DO UNTIL(LAST.B);" caused you a infinite loop. By the first OBS of dataset temp, the first.A and B="N" is true, then do untill loop will never be finished, because the last.B will never reached-----&lt;BR /&gt;
the last.B will be true after two interations, but the program will never get there.</description>
    <pubDate>Mon, 11 Jan 2010 17:42:49 GMT</pubDate>
    <dc:creator>SUN59338</dc:creator>
    <dc:date>2010-01-11T17:42:49Z</dc:date>
    <item>
      <title>Infinite Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Infinite-Loop/m-p/38847#M7838</link>
      <description>In the following code the statement  DO UNTIL(LAST,B)  run into an infinite loop( wait 2 min and the program still running).&lt;BR /&gt;
&lt;BR /&gt;
DATA TEST;&lt;BR /&gt;
 INPUT A $ B $;&lt;BR /&gt;
&lt;BR /&gt;
DATALINES;&lt;BR /&gt;
JOHN Y&lt;BR /&gt;
BETTY N&lt;BR /&gt;
JOHN N&lt;BR /&gt;
BETTY N&lt;BR /&gt;
BETTY N&lt;BR /&gt;
ERIC N&lt;BR /&gt;
HALLY N&lt;BR /&gt;
HALLY Y&lt;BR /&gt;
HALLY N&lt;BR /&gt;
MARY Y&lt;BR /&gt;
ERIC N&lt;BR /&gt;
;&lt;BR /&gt;
RUN;&lt;BR /&gt;
PROC SORT OUT=TEMP; BY A DESCENDING B;&lt;BR /&gt;
RUN;&lt;BR /&gt;
&lt;BR /&gt;
DATA OUT1 ;&lt;BR /&gt;
  SET TEMP; BY A DESCENDING B;&lt;BR /&gt;
   &lt;BR /&gt;
	   IF FIRST.A AND B IN('Y','N') THEN OUTPUT ;&lt;BR /&gt;
	    ELSE IF FIRST.A AND B='N' THEN DO UNTIL(LAST.B);&lt;BR /&gt;
		   OUTPUT;&lt;BR /&gt;
		END;&lt;BR /&gt;
	     &lt;BR /&gt;
RUN;&lt;BR /&gt;
&lt;BR /&gt;
	  &lt;BR /&gt;
All I want is the output&lt;BR /&gt;
&lt;BR /&gt;
                                                  A      B&lt;BR /&gt;
&lt;BR /&gt;
                                              BETTY    N&lt;BR /&gt;
                                              BETTY    N&lt;BR /&gt;
                                              BETTY    N&lt;BR /&gt;
                                              ERIC      N&lt;BR /&gt;
                                              ERIC      N&lt;BR /&gt;
                                              HALLY   Y&lt;BR /&gt;
                                             JOHN      Y&lt;BR /&gt;
                                             MARY     Y&lt;BR /&gt;
&lt;BR /&gt;
Why DO UNTIL(LAST.B) is not correct ? Any idea on what should be the correct code to achieve this output?&lt;BR /&gt;
&lt;BR /&gt;
Thanks&lt;BR /&gt;
David</description>
      <pubDate>Mon, 11 Jan 2010 15:00:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Infinite-Loop/m-p/38847#M7838</guid>
      <dc:creator>Kwok</dc:creator>
      <dc:date>2010-01-11T15:00:22Z</dc:date>
    </item>
    <item>
      <title>Re: Infinite Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Infinite-Loop/m-p/38848#M7839</link>
      <description>Your do loop is acting on a single observation, so you will never hit last.b&lt;BR /&gt;
&lt;BR /&gt;
I think you just want else if last.b then output;</description>
      <pubDate>Mon, 11 Jan 2010 17:28:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Infinite-Loop/m-p/38848#M7839</guid>
      <dc:creator>Flip</dc:creator>
      <dc:date>2010-01-11T17:28:19Z</dc:date>
    </item>
    <item>
      <title>Re: Infinite Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Infinite-Loop/m-p/38849#M7840</link>
      <description>the line "ELSE IF FIRST.A AND B='N' THEN DO UNTIL(LAST.B);" caused you a infinite loop. By the first OBS of dataset temp, the first.A and B="N" is true, then do untill loop will never be finished, because the last.B will never reached-----&lt;BR /&gt;
the last.B will be true after two interations, but the program will never get there.</description>
      <pubDate>Mon, 11 Jan 2010 17:42:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Infinite-Loop/m-p/38849#M7840</guid>
      <dc:creator>SUN59338</dc:creator>
      <dc:date>2010-01-11T17:42:49Z</dc:date>
    </item>
    <item>
      <title>Re: Infinite Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Infinite-Loop/m-p/38850#M7841</link>
      <description>And, consider where your SET statement is located, relative to the DO UNTIL / END logic -- your DATA step flow will not iterate back to the top without encountering a SET / BY operation.&lt;BR /&gt;
&lt;BR /&gt;
Suggest you re-think your DATA step flow.  Also, make use of SAS diagnostic statements (one or more), such as:&lt;BR /&gt;
&lt;BR /&gt;
PUTLOG "&amp;gt;DIAG-nnn&amp;gt;"_ALL_;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
at important points (you increment "nnn" for identification in the log) in your DATA step so you can see how the flow is going at any one point.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Mon, 11 Jan 2010 18:15:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Infinite-Loop/m-p/38850#M7841</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-01-11T18:15:37Z</dc:date>
    </item>
    <item>
      <title>Re: Infinite Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Infinite-Loop/m-p/38851#M7842</link>
      <description>Thanks to all your explanation.</description>
      <pubDate>Mon, 11 Jan 2010 18:32:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Infinite-Loop/m-p/38851#M7842</guid>
      <dc:creator>Kwok</dc:creator>
      <dc:date>2010-01-11T18:32:34Z</dc:date>
    </item>
    <item>
      <title>Re: Infinite Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Infinite-Loop/m-p/38852#M7843</link>
      <description>You may try this, even If there are more posibble values exist for B :&lt;BR /&gt;
&lt;BR /&gt;
DATA TEST;&lt;BR /&gt;
INPUT A $ B $;&lt;BR /&gt;
&lt;BR /&gt;
DATALINES;&lt;BR /&gt;
JOHN Y&lt;BR /&gt;
BETTY N&lt;BR /&gt;
JOHN N&lt;BR /&gt;
BETTY N&lt;BR /&gt;
BETTY N&lt;BR /&gt;
ERIC N&lt;BR /&gt;
HALLY N&lt;BR /&gt;
HALLY Y&lt;BR /&gt;
HALLY N&lt;BR /&gt;
MARY Y&lt;BR /&gt;
ERIC N&lt;BR /&gt;
HALLY Q&lt;BR /&gt;
HALLY Q&lt;BR /&gt;
LOHN Z&lt;BR /&gt;
;&lt;BR /&gt;
RUN;&lt;BR /&gt;
PROC SORT OUT=TEMP; BY A DESCENDING B;&lt;BR /&gt;
RUN;&lt;BR /&gt;
&lt;BR /&gt;
DATA OUT1 ;&lt;BR /&gt;
SET TEMP; &lt;BR /&gt;
BY A DESCENDING B;&lt;BR /&gt;
&lt;BR /&gt;
DROP flag;&lt;BR /&gt;
RETAIN flag 0;&lt;BR /&gt;
&lt;BR /&gt;
IF FIRST.A THEN DO;&lt;BR /&gt;
	IF B='N' THEN DO;&lt;BR /&gt;
		flag=1;&lt;BR /&gt;
		IF not LAST.B THEN OUTPUT;&lt;BR /&gt;
	END;&lt;BR /&gt;
	ELSE DO; &lt;BR /&gt;
		flag=0;&lt;BR /&gt;
		IF B = 'Y' then output;		&lt;BR /&gt;
	END; &lt;BR /&gt;
END;&lt;BR /&gt;
&lt;BR /&gt;
ELSE IF B='N' AND FLAG=1 THEN OUTPUT;&lt;BR /&gt;
 &lt;BR /&gt;
&lt;BR /&gt;
RUN;</description>
      <pubDate>Mon, 11 Jan 2010 18:41:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Infinite-Loop/m-p/38852#M7843</guid>
      <dc:creator>SUN59338</dc:creator>
      <dc:date>2010-01-11T18:41:15Z</dc:date>
    </item>
    <item>
      <title>Re: Infinite Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Infinite-Loop/m-p/38853#M7844</link>
      <description>the reason for infinite looping was exactly as other people pointed out.&lt;BR /&gt;
&lt;BR /&gt;
if I understand you correctly, what you wanted is that, for any name (A) if the B value is 'Y' then output only once, otherwise output all records (i.e. B='N').&lt;BR /&gt;
&lt;BR /&gt;
my approach is as follows and see if this works:&lt;BR /&gt;
&lt;BR /&gt;
proc sort data=test out=temp;&lt;BR /&gt;
by A descending B;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data out1;&lt;BR /&gt;
 set temp;&lt;BR /&gt;
 by A descending B;&lt;BR /&gt;
&lt;BR /&gt;
 if not first.B and B='Y'  then delete;&lt;BR /&gt;
run;</description>
      <pubDate>Thu, 21 Jan 2010 18:40:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Infinite-Loop/m-p/38853#M7844</guid>
      <dc:creator>abdullala</dc:creator>
      <dc:date>2010-01-21T18:40:44Z</dc:date>
    </item>
  </channel>
</rss>

