<?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: do loop leave in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/do-loop-leave/m-p/549703#M152566</link>
    <description>&lt;P&gt;I also tried doing the same thing inside a macro with no luck.&amp;nbsp; I tried using:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%goto leave;&lt;/P&gt;
&lt;P&gt;%end;&lt;/P&gt;
&lt;P&gt;leave:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and that didn't work either.&lt;/P&gt;</description>
    <pubDate>Tue, 09 Apr 2019 16:46:12 GMT</pubDate>
    <dc:creator>Steelers_In_DC</dc:creator>
    <dc:date>2019-04-09T16:46:12Z</dc:date>
    <item>
      <title>do loop leave</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop-leave/m-p/549686#M152556</link>
      <description>&lt;P&gt;I am trying to stop a do loop once a value is divisible by three.&amp;nbsp; I have never come across the leave statement before but it looked like a good fit.&amp;nbsp; I'm running the code below and not getting the desired output.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There's no error but the code runs as if the line with 'leave' was commented out.&amp;nbsp; If anyone can provide any insight on this function and what I'm doing wrong I'd appreciate it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data have;&lt;BR /&gt;input id mob co;&lt;BR /&gt;cards;&lt;BR /&gt;1 35 1&lt;BR /&gt;1 34 1&lt;BR /&gt;1 33 1&lt;BR /&gt;1 32 1&lt;BR /&gt;2 33 1&lt;BR /&gt;2 32 1&lt;BR /&gt;2 31 1&lt;BR /&gt;2 30 1&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;data want;&lt;BR /&gt;input id mob co;&lt;BR /&gt;cards;&lt;BR /&gt;1 35 0&lt;BR /&gt;1 34 0&lt;BR /&gt;1 33 1&lt;BR /&gt;1 32 1&lt;BR /&gt;2 33 1&lt;BR /&gt;2 32 1&lt;BR /&gt;2 31 1&lt;BR /&gt;2 30 1&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;data getting;&lt;BR /&gt;input id mob co;&lt;BR /&gt;cards;&lt;BR /&gt;1 35 0&lt;BR /&gt;1 34 0&lt;BR /&gt;1 33 1&lt;BR /&gt;1 32 0&lt;BR /&gt;2 33 1&lt;BR /&gt;2 32 0&lt;BR /&gt;2 31 0&lt;BR /&gt;2 30 1&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;data code;&lt;BR /&gt;set have;&lt;BR /&gt;by id;&lt;BR /&gt;do i = 1 to 3;&lt;BR /&gt;if mod(mob,3) ne 0 then co = 0;&lt;BR /&gt;if mod(mob,3) = 0 then leave;&lt;BR /&gt;end;&lt;BR /&gt;drop i;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Apr 2019 16:23:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop-leave/m-p/549686#M152556</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2019-04-09T16:23:22Z</dc:date>
    </item>
    <item>
      <title>Re: do loop leave</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop-leave/m-p/549690#M152558</link>
      <description>What exactly are you looping over there? You only have one variable and I is never used?</description>
      <pubDate>Tue, 09 Apr 2019 16:31:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop-leave/m-p/549690#M152558</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-04-09T16:31:19Z</dc:date>
    </item>
    <item>
      <title>Re: do loop leave</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop-leave/m-p/549702#M152565</link>
      <description>&lt;P&gt;So right, sorry I forgot an important step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data code;&lt;BR /&gt;set have;&lt;BR /&gt;by id;&lt;BR /&gt;count + 1;&lt;BR /&gt;if first.id then count = 1;&lt;BR /&gt;do i = 1 to 3;&lt;BR /&gt;if count = i and mod(mob,3) ne 0 then co = 0;&lt;BR /&gt;if mod(mob,3) = 0 then leave;&lt;BR /&gt;end;&lt;BR /&gt;drop i count;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Apr 2019 16:44:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop-leave/m-p/549702#M152565</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2019-04-09T16:44:41Z</dc:date>
    </item>
    <item>
      <title>Re: do loop leave</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop-leave/m-p/549703#M152566</link>
      <description>&lt;P&gt;I also tried doing the same thing inside a macro with no luck.&amp;nbsp; I tried using:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%goto leave;&lt;/P&gt;
&lt;P&gt;%end;&lt;/P&gt;
&lt;P&gt;leave:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and that didn't work either.&lt;/P&gt;</description>
      <pubDate>Tue, 09 Apr 2019 16:46:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop-leave/m-p/549703#M152566</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2019-04-09T16:46:12Z</dc:date>
    </item>
    <item>
      <title>Re: do loop leave</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop-leave/m-p/549711#M152573</link>
      <description>&lt;P&gt;I still don't understand why you have a loop.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think this is what you want:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data code;
set have (drop=co);
by id;
retain co;
if first.id then co=0;

if mod(mob,3)=0 and co=0 then co=1;

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 Apr 2019 17:01:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop-leave/m-p/549711#M152573</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-04-09T17:01:35Z</dc:date>
    </item>
    <item>
      <title>Re: do loop leave</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop-leave/m-p/549715#M152577</link>
      <description>&lt;P&gt;This is an oversimplified version of the real data.&amp;nbsp; CO represents a charge-off amount for a customer.&amp;nbsp; I cannot drop the co variable in the set statement, it's not binary.&lt;/P&gt;</description>
      <pubDate>Tue, 09 Apr 2019 17:06:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop-leave/m-p/549715#M152577</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2019-04-09T17:06:07Z</dc:date>
    </item>
    <item>
      <title>Re: do loop leave</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop-leave/m-p/549722#M152583</link>
      <description>&lt;P&gt;I'm moving on from the leave option.&amp;nbsp; I think this works fine:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; code;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; have;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;by&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; id;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;count + &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; first.id &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; count = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;i = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;do&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;while&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(i &amp;lt; &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;4&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; count = i &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;and&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; mod(mob,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;3&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;) ne &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; co = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; mod(mob,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;3&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;) = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; i = i + count;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;i + &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;end&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;drop&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; count i;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Apr 2019 17:29:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop-leave/m-p/549722#M152583</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2019-04-09T17:29:22Z</dc:date>
    </item>
    <item>
      <title>Re: do loop leave</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop-leave/m-p/549724#M152584</link>
      <description>You need to specify a little more of the logic.  There is nothing in the program (let alone inside the loop) that could change the value of&lt;BR /&gt;&lt;BR /&gt;mod(mob,3)</description>
      <pubDate>Tue, 09 Apr 2019 17:32:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop-leave/m-p/549724#M152584</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-04-09T17:32:51Z</dc:date>
    </item>
  </channel>
</rss>

