<?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: Break/Continue statements in proc iml loops in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Break-Continue-statements-in-proc-iml-loops/m-p/337510#M3310</link>
    <description>&lt;P&gt;That was the trick I was looking for. Nice!&lt;/P&gt;</description>
    <pubDate>Thu, 02 Mar 2017 19:15:25 GMT</pubDate>
    <dc:creator>Notifications</dc:creator>
    <dc:date>2017-03-02T19:15:25Z</dc:date>
    <item>
      <title>Break/Continue statements in proc iml loops</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Break-Continue-statements-in-proc-iml-loops/m-p/337472#M3306</link>
      <description>&lt;P&gt;What is the Proc IML equivalent of break/continue statments found in other languages, such as MATLAB and Python?&lt;/P&gt;</description>
      <pubDate>Thu, 02 Mar 2017 17:45:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Break-Continue-statements-in-proc-iml-loops/m-p/337472#M3306</guid>
      <dc:creator>Notifications</dc:creator>
      <dc:date>2017-03-02T17:45:02Z</dc:date>
    </item>
    <item>
      <title>Re: Break/Continue statements in proc iml loops</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Break-Continue-statements-in-proc-iml-loops/m-p/337493#M3307</link>
      <description>&lt;P&gt;In the SAS DATA step, you can use &lt;A href="http://support.sas.com/documentation/cdl/en/lestmtsref/69738/HTML/default/viewer.htm#n0vupy1vhs8gosn1tjd3zg8dtf76.htm" target="_self"&gt;the LEAVE and CONTINUE statements.&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DO loops in SAS/IML do not support those statements. However, you can &lt;A href="http://support.sas.com/documentation/cdl/en/imlug/68150/HTML/default/viewer.htm#imlug_programstatements_sect008.htm" target="_self"&gt;use a DO UNTIL loop&lt;/A&gt; to break out of a loop when a certain condition is met. &amp;nbsp;You can &lt;A href="http://support.sas.com/documentation/cdl/en/imlug/68150/HTML/default/viewer.htm#imlug_programstatements_sect009.htm" target="_self"&gt;use a GOTO/LABEL statement &lt;/A&gt;to jump to the end of a loop and continue with the next iteration when a certain condition is met. &amp;nbsp;Here is an example of each construct:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* simulate the roll of a six-sided die */
proc iml;
call randseed(54321);
die = 1:6;

/* BREAK: Exit loop when a condition is true */
done = 0;  /* set flag to FALSE */
do i = 1 to 1000 until(done);
   roll = sample(die, 1);   /* roll die 1 time */
   if roll = 6 then done = 1;
end;
print i " rolls until roll = " roll;


/* CONTINUE: Skip the body and go to the next iteration 
             when a condition is true */
count = 0;
do i = 1 to 1000;
   roll = sample(die, 1);   /* roll die 1 time */
   if roll = 6 then goto CONTINUE;
   count = count + 1;
CONTINUE:
end;
print count " rolls were not 6";&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Mar 2017 18:48:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Break-Continue-statements-in-proc-iml-loops/m-p/337493#M3307</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2017-03-02T18:48:06Z</dc:date>
    </item>
    <item>
      <title>Re: Break/Continue statements in proc iml loops</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Break-Continue-statements-in-proc-iml-loops/m-p/337497#M3308</link>
      <description>&lt;P&gt;You can also use a modification of Rick's CONTINUE example to break out of a loop immediately.&amp;nbsp; This would only be important if you had other code in the loop that you didn't want to execute&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;/* BREAK: exit loop immediately */
count = 0;
do i = 1 to 1000;
   roll = sample(die, 1);   /* roll die 1 time */
   if roll = 6 then goto BREAK;
   count = count + 1;
   /* other statements */
end;
BREAK:
print count "rolls before rolling a 6";&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Mar 2017 18:55:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Break-Continue-statements-in-proc-iml-loops/m-p/337497#M3308</guid>
      <dc:creator>dougc</dc:creator>
      <dc:date>2017-03-02T18:55:43Z</dc:date>
    </item>
    <item>
      <title>Re: Break/Continue statements in proc iml loops</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Break-Continue-statements-in-proc-iml-loops/m-p/337508#M3309</link>
      <description>&lt;P&gt;Well, kinda.&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/91063"&gt;@dougc&lt;/a&gt;'s code works if you are in a module but in open code it is invalid. The&amp;nbsp;doc says "The GOTO statement must be inside a module or DO group. These statements must be able to resolve the referenced label within the current unit of statements." &amp;nbsp;What that means is that you can't jump out of a do loop&amp;nbsp;unless the GOTO statement and label are both within&amp;nbsp;some larger nested DO/END block that you submit, like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do;
   /* BREAK: exit loop immediately */
   count = 0;
   do i = 1 to 1000;
      roll = sample(die, 1);   /* roll die 1 time */
      if roll = 6 then goto BREAK;
      count = count + 1;
      /* other statements */
   end;
   BREAK:
   print count "rolls before rolling a 6"; 
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Personally, I do not recommend jumping outside of a loop. I think the DO UNTIL syntax is clearer and easier to read.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Mar 2017 19:14:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Break-Continue-statements-in-proc-iml-loops/m-p/337508#M3309</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2017-03-02T19:14:04Z</dc:date>
    </item>
    <item>
      <title>Re: Break/Continue statements in proc iml loops</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Break-Continue-statements-in-proc-iml-loops/m-p/337510#M3310</link>
      <description>&lt;P&gt;That was the trick I was looking for. Nice!&lt;/P&gt;</description>
      <pubDate>Thu, 02 Mar 2017 19:15:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Break-Continue-statements-in-proc-iml-loops/m-p/337510#M3310</guid>
      <dc:creator>Notifications</dc:creator>
      <dc:date>2017-03-02T19:15:25Z</dc:date>
    </item>
  </channel>
</rss>

