<?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 break from the do loop in SAS IML in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-break-from-the-do-loop-in-SAS-IML/m-p/374892#M3590</link>
    <description>&lt;P&gt;Did you read the article that I linked to? &amp;nbsp;It shows two ways to do this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. protect the remainder of the loop with&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if ( ^done ) then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;/* stuff you don't want to execute */&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. Use the GOTO statement to jump to the end of the loop.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
x=-3;
y = j(1, 10, .);
done = 0;
do i = 1 to 10 while( ^done );
   if x&amp;gt;0 then do;
      y[i] = sqrt(x);                            
      print y;                              
      done = 1;  /* set exit criterion */
      goto breakout;
   end;
   else do;
      y[i]=x#2;
      print y;
   end;
   x = x + 1;  /* change x? */
   breakout:
end;
print x;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Please study the links and code so that you can learn how to transfer&amp;nbsp;your MATLAB knowledge into SAS/IML. You&amp;nbsp;might also want to read &lt;A href="http://blogs.sas.com/content/iml/2014/08/11/ten-tips-for-learning-sasiml.html" target="_self"&gt;"Ten tips for learning the SAS/IML language."&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 11 Jul 2017 11:19:02 GMT</pubDate>
    <dc:creator>Rick_SAS</dc:creator>
    <dc:date>2017-07-11T11:19:02Z</dc:date>
    <item>
      <title>How to break from the do loop in SAS IML</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-break-from-the-do-loop-in-SAS-IML/m-p/374859#M3587</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to translate a matlab code into SAS IML but have some issues on the&amp;nbsp;translating break function&amp;nbsp;in a do loop.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basically what I would like to do is like below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc iml;&lt;BR /&gt;x=-3;&lt;BR /&gt;do i = 1 to 10;&lt;BR /&gt;if x&amp;gt;0 then do;&lt;BR /&gt;y[i] = sqrt(x);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;print y;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;goto break;&lt;BR /&gt;else do;&lt;BR /&gt;y[i]=x#2;&lt;BR /&gt;print y;&lt;BR /&gt;end;&lt;BR /&gt;print x;&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;break:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code above does not work properly, I want to make it break from the do loop when x is&amp;nbsp;positive so that only y is printed. If x is negative, then both x and y will be printed. Please if there are other functions in IML can&amp;nbsp;realize this function.&amp;nbsp;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jul 2017 10:07:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-break-from-the-do-loop-in-SAS-IML/m-p/374859#M3587</guid>
      <dc:creator>jazhang</dc:creator>
      <dc:date>2017-07-11T10:07:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to break from the do loop in SAS IML</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-break-from-the-do-loop-in-SAS-IML/m-p/374867#M3588</link>
      <description>&lt;P&gt;&lt;A href="http://blogs.sas.com/content/iml/2017/03/15/leave-continue-sas.html" target="_self"&gt;The SAS/IML supports the DO WHILE and DO UNTIL statements&lt;/A&gt;, which are logically equivalent to the&amp;nbsp;BREAK statement,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your program does not change the value of x within the loop, so I'm not sure what logic you are trying to accomplish, but the general idea is&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
x=-3;
y = j(1, 10, .);
done = 0;
do i = 1 to 10 while( ^done );
   if x&amp;gt;0 then do;
      y[i] = sqrt(x);                            
      print y;                              
      done = 1;  /* set exit criterion */
   end;
   else do;
      y[i]=x#2;
      print y;
   end;
   x = x + 1;  /* change x? */
end;
print x;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 11 Jul 2017 10:28:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-break-from-the-do-loop-in-SAS-IML/m-p/374867#M3588</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2017-07-11T10:28:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to break from the do loop in SAS IML</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-break-from-the-do-loop-in-SAS-IML/m-p/374887#M3589</link>
      <description>Thanks for the quick reply, Rick! This is only a simplified code of original Matlab code but does the same function. But I would like to immediately jump out of the loop after y is printed when x is positive. But I think your code will still run to the end of the current loop. Thanks!</description>
      <pubDate>Tue, 11 Jul 2017 11:03:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-break-from-the-do-loop-in-SAS-IML/m-p/374887#M3589</guid>
      <dc:creator>jazhang</dc:creator>
      <dc:date>2017-07-11T11:03:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to break from the do loop in SAS IML</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-break-from-the-do-loop-in-SAS-IML/m-p/374892#M3590</link>
      <description>&lt;P&gt;Did you read the article that I linked to? &amp;nbsp;It shows two ways to do this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. protect the remainder of the loop with&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if ( ^done ) then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;/* stuff you don't want to execute */&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. Use the GOTO statement to jump to the end of the loop.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
x=-3;
y = j(1, 10, .);
done = 0;
do i = 1 to 10 while( ^done );
   if x&amp;gt;0 then do;
      y[i] = sqrt(x);                            
      print y;                              
      done = 1;  /* set exit criterion */
      goto breakout;
   end;
   else do;
      y[i]=x#2;
      print y;
   end;
   x = x + 1;  /* change x? */
   breakout:
end;
print x;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Please study the links and code so that you can learn how to transfer&amp;nbsp;your MATLAB knowledge into SAS/IML. You&amp;nbsp;might also want to read &lt;A href="http://blogs.sas.com/content/iml/2014/08/11/ten-tips-for-learning-sasiml.html" target="_self"&gt;"Ten tips for learning the SAS/IML language."&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jul 2017 11:19:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-break-from-the-do-loop-in-SAS-IML/m-p/374892#M3590</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2017-07-11T11:19:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to break from the do loop in SAS IML</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-break-from-the-do-loop-in-SAS-IML/m-p/375173#M3594</link>
      <description>&lt;P&gt;Thanks Rick, this is very helpful!&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2017 01:38:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-break-from-the-do-loop-in-SAS-IML/m-p/375173#M3594</guid>
      <dc:creator>jazhang</dc:creator>
      <dc:date>2017-07-12T01:38:42Z</dc:date>
    </item>
  </channel>
</rss>

