<?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: Correct use of DO WHILE loop? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Correct-use-of-DO-WHILE-loop/m-p/757253#M239113</link>
    <description>&lt;P&gt;Ah, good point&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think, though, that in addition to the point raised by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;the erroneous semi-colon will need to be first removed before even the first observation is processed correctly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
    <pubDate>Tue, 27 Jul 2021 18:09:53 GMT</pubDate>
    <dc:creator>jimbarbour</dc:creator>
    <dc:date>2021-07-27T18:09:53Z</dc:date>
    <item>
      <title>Correct use of DO WHILE loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Correct-use-of-DO-WHILE-loop/m-p/757212#M239107</link>
      <description>&lt;P&gt;Esteemed Advisers,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I know I'll be embarassed when the answer comes back on this question:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The goal of the attached code is to generate 10 random meteors within each of two volumes of sky. Each meteor must be at least 10 units in length.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code produces 10 satisfactory meteors for Target A but none for Target B.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is the correct way to formulate this DO LOOP to process both TARGET A and B in dataset TargetArea?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Gene&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data TargetArea;
Input Target $ txmin txmax tymin tymax tzmin tzmax;
datalines;
A 0 5 0 5 70 120
B 0 10 0 10 70 120
run;
/* SAS macro from Wicklin for generating Random Numbers between a Min and Max */
%macro RandBetween(min, max);
   (&amp;amp;min + floor((1+&amp;amp;max-&amp;amp;min)*rand("uniform")))
%mend;
data Random_Meteors (keep= target meteorct1 meteorct2);
set work.targetarea;
meteorct1=0;
do while (meteorct2&amp;lt;10);
   TX_Start = %RandBetween(txmin, txmax);
   TY_Start = %RandBetween(tymin, tymax);
   TZ_Start = %RandBetween(tzmin, tzmax);
   TX_End = %RandBetween(txmin, txmax);
   TY_End = %RandBetween(tymin, tymax);
   TZ_End = %RandBetween(tzmin, tzmax);
   meteorct1+1;
   TrackLength=sqrt((TX_Start-TX_End)**2+(TY_Start-TY_End)**2+(TZ_Start-TZ_End)**2);
   /* if tracklength&amp;lt;10, generate another meteor until it finds one with tracklength &amp;gt;=10*/
   if tracklength&amp;lt;10 then continue;
   else;
   meteorct2+1;
   output;
end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 27 Jul 2021 17:48:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Correct-use-of-DO-WHILE-loop/m-p/757212#M239107</guid>
      <dc:creator>genemroz</dc:creator>
      <dc:date>2021-07-27T17:48:53Z</dc:date>
    </item>
    <item>
      <title>Re: Correct use of DO WHILE loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Correct-use-of-DO-WHILE-loop/m-p/757243#M239109</link>
      <description>&lt;P&gt;You have an error in your IF statement.&amp;nbsp; There is a semi-colon after the "else".&amp;nbsp; That means that Meteor2 is incremented unconditionally (every time) rather than checking for meteors of the proper size.&amp;nbsp; Delete the semi colon and re-run.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   if tracklength&amp;lt;10 then continue;
   else;
   meteorct2+1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Jim&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Jul 2021 18:02:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Correct-use-of-DO-WHILE-loop/m-p/757243#M239109</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2021-07-27T18:02:32Z</dc:date>
    </item>
    <item>
      <title>Re: Correct use of DO WHILE loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Correct-use-of-DO-WHILE-loop/m-p/757244#M239110</link>
      <description>&lt;P&gt;You are using the summing statement&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;meteorct2+1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which will retain the value of 10 achieved in the first observation as the starting value for the 2nd obs.&amp;nbsp; As a result the "do while (meteorct2&amp;lt;10);" loop will never be activated in the 2nd obs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;meteorct2=sum(meteorct2,1);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;instead.&amp;nbsp; It will not retain values across observations.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Jul 2021 18:12:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Correct-use-of-DO-WHILE-loop/m-p/757244#M239110</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-07-27T18:12:48Z</dc:date>
    </item>
    <item>
      <title>Re: Correct use of DO WHILE loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Correct-use-of-DO-WHILE-loop/m-p/757253#M239113</link>
      <description>&lt;P&gt;Ah, good point&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think, though, that in addition to the point raised by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;the erroneous semi-colon will need to be first removed before even the first observation is processed correctly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Tue, 27 Jul 2021 18:09:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Correct-use-of-DO-WHILE-loop/m-p/757253#M239113</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2021-07-27T18:09:53Z</dc:date>
    </item>
    <item>
      <title>Re: Correct use of DO WHILE loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Correct-use-of-DO-WHILE-loop/m-p/757270#M239114</link>
      <description>&lt;P&gt;You've received good findings from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/37107"&gt;@jimbarbour&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;.&amp;nbsp; I'll just add that the DATA step debugger (available in SAS Enterprise Guide and SAS Studio) can be used to find logic/behavior errors like this!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dsdebug.jpg" style="width: 992px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/61922iA82BE4F45310E30C/image-size/large?v=v2&amp;amp;px=999" role="button" title="dsdebug.jpg" alt="dsdebug.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Jul 2021 18:45:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Correct-use-of-DO-WHILE-loop/m-p/757270#M239114</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2021-07-27T18:45:25Z</dc:date>
    </item>
    <item>
      <title>Re: Correct use of DO WHILE loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Correct-use-of-DO-WHILE-loop/m-p/757406#M239115</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4"&gt;@ChrisHemedinger&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The interactive debugger is a truly beautiful feature of Enterprise Guide.&amp;nbsp; I really don't consider Enterprise Guide to have become excellent until version 7.1.3 (as I recall) came out which included the debugger.&amp;nbsp; Versions 5.1 up to 7.1.2 were good but not excellent.&amp;nbsp; Versions prior to 5.1, uh, well, they weren't so good.&amp;nbsp; &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Tue, 27 Jul 2021 18:59:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Correct-use-of-DO-WHILE-loop/m-p/757406#M239115</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2021-07-27T18:59:14Z</dc:date>
    </item>
    <item>
      <title>Re: Correct use of DO WHILE loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Correct-use-of-DO-WHILE-loop/m-p/757476#M239116</link>
      <description>Thanks for this tip.  I was not aware of the Data step debugger but will certainly make use of it in the future.&lt;BR /&gt;&lt;BR /&gt;Gene</description>
      <pubDate>Tue, 27 Jul 2021 19:33:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Correct-use-of-DO-WHILE-loop/m-p/757476#M239116</guid>
      <dc:creator>genemroz</dc:creator>
      <dc:date>2021-07-27T19:33:38Z</dc:date>
    </item>
    <item>
      <title>Re: Correct use of DO WHILE loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Correct-use-of-DO-WHILE-loop/m-p/757478#M239117</link>
      <description>Thanks for spotting this.  Semi-colons tend become invisible after awhile.</description>
      <pubDate>Tue, 27 Jul 2021 19:34:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Correct-use-of-DO-WHILE-loop/m-p/757478#M239117</guid>
      <dc:creator>genemroz</dc:creator>
      <dc:date>2021-07-27T19:34:50Z</dc:date>
    </item>
  </channel>
</rss>

