<?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 While Loop Not executing in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Do-While-Loop-Not-executing/m-p/731095#M227725</link>
    <description>&lt;P&gt;Looks like you are expecting&amp;nbsp;&lt;SPAN&gt;switch_in to increment between rows. You need to add a RETAIN statement to make this happen (position is not important):&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;retain switch_in;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Sat, 03 Apr 2021 01:20:34 GMT</pubDate>
    <dc:creator>SASKiwi</dc:creator>
    <dc:date>2021-04-03T01:20:34Z</dc:date>
    <item>
      <title>Do While Loop Not executing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-While-Loop-Not-executing/m-p/731094#M227724</link>
      <description>&lt;P&gt;Hi experts!&amp;nbsp; I need help with this while loop. Can u tell visually what is wrong with it? It should iterate through two arrays (flow_field and bal_field) and loop while "switch_in" is more than zero:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data do_until;&lt;BR /&gt;set money_table;&lt;/P&gt;&lt;P&gt;array flow_field [*]&amp;nbsp; _from_1&amp;nbsp; _from_2&amp;nbsp; _from_3&amp;nbsp; &amp;nbsp;_from_4&amp;nbsp; _from_5 ;&lt;BR /&gt;array bal_field [*]&amp;nbsp; &amp;nbsp;bal_1 bal_2 bal_3&amp;nbsp; bal_4&amp;nbsp; bal_5 ;&lt;/P&gt;&lt;P&gt;switch_in = 100000;&lt;/P&gt;&lt;P&gt;do while (switch_in &amp;gt; 0);&lt;BR /&gt;&amp;nbsp; do i=1 to 5;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;if bal_field[i] lt 0 and bal_field[i] ne . then do;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;flow_field[i] = min(switch_in, abs(bal_field[i]));&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; switch_in = switch_in - (abs(bal_field[i]));&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; end;&lt;BR /&gt;&amp;nbsp; end;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Sat, 03 Apr 2021 01:07:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-While-Loop-Not-executing/m-p/731094#M227724</guid>
      <dc:creator>jcdataguy</dc:creator>
      <dc:date>2021-04-03T01:07:04Z</dc:date>
    </item>
    <item>
      <title>Re: Do While Loop Not executing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-While-Loop-Not-executing/m-p/731095#M227725</link>
      <description>&lt;P&gt;Looks like you are expecting&amp;nbsp;&lt;SPAN&gt;switch_in to increment between rows. You need to add a RETAIN statement to make this happen (position is not important):&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;retain switch_in;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 03 Apr 2021 01:20:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-While-Loop-Not-executing/m-p/731095#M227725</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2021-04-03T01:20:34Z</dc:date>
    </item>
    <item>
      <title>Re: Do While Loop Not executing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-While-Loop-Not-executing/m-p/731096#M227726</link>
      <description>&lt;P&gt;Thanks for your reply &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13976"&gt;@SASKiwi&lt;/a&gt;&amp;nbsp;.&amp;nbsp; But I want Switch_In to decrease with each passing of teh loop until it reaches 0. It loop it's supposed to iterate for those bal_flow that are less than 0.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 03 Apr 2021 01:35:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-While-Loop-Not-executing/m-p/731096#M227726</guid>
      <dc:creator>jcdataguy</dc:creator>
      <dc:date>2021-04-03T01:35:00Z</dc:date>
    </item>
    <item>
      <title>Re: Do While Loop Not executing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-While-Loop-Not-executing/m-p/731097#M227727</link>
      <description>&lt;P&gt;One possibility (at least in theory):&amp;nbsp; Once you hit an observation that has all non-negative balance fields, the logic fails to change switch_in.&amp;nbsp; The program becomes an infinite loop.&lt;/P&gt;</description>
      <pubDate>Sat, 03 Apr 2021 02:23:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-While-Loop-Not-executing/m-p/731097#M227727</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2021-04-03T02:23:19Z</dc:date>
    </item>
    <item>
      <title>Re: Do While Loop Not executing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-While-Loop-Not-executing/m-p/731098#M227728</link>
      <description>&lt;P&gt;HERE IS SOME SAMPLE DATA:&lt;/P&gt;&lt;P&gt;The total values in the _from fields cannot exceed the switch_in values&lt;/P&gt;</description>
      <pubDate>Sat, 03 Apr 2021 02:31:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-While-Loop-Not-executing/m-p/731098#M227728</guid>
      <dc:creator>jcdataguy</dc:creator>
      <dc:date>2021-04-03T02:31:20Z</dc:date>
    </item>
    <item>
      <title>Re: Do While Loop Not executing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-While-Loop-Not-executing/m-p/731099#M227729</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/373301"&gt;@jcdataguy&lt;/a&gt; - An increment can be either positive or negative but you will still need the RETAIN for it to work.&lt;/P&gt;</description>
      <pubDate>Sat, 03 Apr 2021 02:51:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-While-Loop-Not-executing/m-p/731099#M227729</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2021-04-03T02:51:36Z</dc:date>
    </item>
    <item>
      <title>Re: Do While Loop Not executing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-While-Loop-Not-executing/m-p/731111#M227740</link>
      <description>&lt;P&gt;If for a specific row below condition is never true....&lt;/P&gt;
&lt;PRE&gt;if bal_field[i] lt 0 and bal_field[i] ne . then&lt;/PRE&gt;
&lt;P&gt;...then&amp;nbsp;the value for&amp;nbsp;&lt;SPAN&gt;&lt;EM&gt;switch_in&lt;/EM&gt; never changes but remains 100000 which results in an infinite loop.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here some code to test this using the sample data you've posted.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA money_table;
  LENGTH
    BAL_1              8
    BAL_2              8
    BAL_3              8
    BAL_4              8
    BAL_5              8
    total_netbal       8
    _FROM_1            8
    FROM_2             8
    _FROM_3            8
    FROM_4             8
    _FROM_5            8
    SWITCH_IN          8;
  FORMAT
    BAL_1            DOLLAR19.1
    BAL_2            DOLLAR19.1
    BAL_3            DOLLAR19.1
    BAL_4            DOLLAR19.1
    BAL_5            DOLLAR16.2
    total_netbal     DOLLAR19.1
    _FROM_1          DOLLAR19.1
    FROM_2           DOLLAR19.1
    _FROM_3          DOLLAR19.1
    FROM_4           DOLLAR19.1
    _FROM_5          DOLLAR19.1
    SWITCH_IN        BEST12.;
  INFORMAT
    BAL_1            DOLLAR19.
    BAL_2            DOLLAR19.
    BAL_3            DOLLAR19.
    BAL_4            DOLLAR19.
    BAL_5            DOLLAR16.
    total_netbal     DOLLAR19.
    _FROM_1          DOLLAR19.
    FROM_2           DOLLAR19.
    _FROM_3          DOLLAR19.
    FROM_4           DOLLAR19.
    _FROM_5          DOLLAR19.
    SWITCH_IN        BEST12.;
  INFILE DATALINES4
    DLM='7F'x
    MISSOVER
    DSD;
  INPUT
    BAL_1            : BEST32.
    BAL_2            : BEST32.
    BAL_3            : BEST32.
    BAL_4            : BEST32.
    BAL_5            : DOLLAR19.
    total_netbal     : BEST32.
    _FROM_1          : BEST32.
    FROM_2           : BEST32.
    _FROM_3          : BEST32.
    FROM_4           : BEST32.
    _FROM_5          : BEST32.
    SWITCH_IN        : BEST32.;
  DATALINES4;
542.59&amp;#127;58829.64&amp;#127;288.119999999999&amp;#127;.&amp;#127; &amp;#127;59660.35&amp;#127;58829.64&amp;#127;0&amp;#127;.&amp;#127;.&amp;#127;.&amp;#127;5000
899.47&amp;#127;0&amp;#127;.&amp;#127;.&amp;#127; &amp;#127;899.47&amp;#127;0&amp;#127;0&amp;#127;.&amp;#127;.&amp;#127;.&amp;#127;10000
1285.25&amp;#127;79059.13&amp;#127;-4543.95&amp;#127;.&amp;#127; &amp;#127;75800.43&amp;#127;75800.43&amp;#127;3258.70000000001&amp;#127;0&amp;#127;0&amp;#127;3258.70000000001&amp;#127;15000
-61360.7&amp;#127;152471.48&amp;#127;.&amp;#127;.&amp;#127; &amp;#127;91110.78&amp;#127;91110.78&amp;#127;61360.7&amp;#127;61360.7&amp;#127;0&amp;#127;0&amp;#127;20000
8021.21&amp;#127;57220.79&amp;#127;.&amp;#127;34.1599999999999&amp;#127; &amp;#127;65276.16&amp;#127;57220.79&amp;#127;0&amp;#127;.&amp;#127;.&amp;#127;.&amp;#127;25000
-15165.25&amp;#127;40021.09&amp;#127;.&amp;#127;.&amp;#127; &amp;#127;24855.84&amp;#127;24855.84&amp;#127;15165.25&amp;#127;15165.25&amp;#127;0&amp;#127;0&amp;#127;30000
141.04&amp;#127;38611.91&amp;#127;-882.77&amp;#127;.&amp;#127; &amp;#127;37870.18&amp;#127;37870.18&amp;#127;741.729999999996&amp;#127;0&amp;#127;0&amp;#127;741.729999999996&amp;#127;35000
-9890.78&amp;#127;124218.75&amp;#127;.&amp;#127;.&amp;#127; &amp;#127;114327.97&amp;#127;114327.97&amp;#127;9890.78&amp;#127;9890.78&amp;#127;0&amp;#127;0&amp;#127;40000
-15385.88&amp;#127;80865.71&amp;#127;.&amp;#127;.&amp;#127; &amp;#127;65479.83&amp;#127;65479.83&amp;#127;15385.88&amp;#127;15385.88&amp;#127;0&amp;#127;0&amp;#127;45000
;;;;

data do_until;
  obs=_n_;
  set money_table;
  array flow_field [*]  _from_1  _from_2  _from_3   _from_4  _from_5;
  array bal_field [*]   bal_1 bal_2 bal_3  bal_4  bal_5;
  switch_in = 100000;

  do while (switch_in &amp;gt; 0);
    do i=1 to dim(flow_field);
      if bal_field[i] lt 0 and bal_field[i] ne . then
        do;
          flow_field[i] = min(switch_in, abs(bal_field[i]));
          switch_in = switch_in - (abs(bal_field[i]));
/*          output;*/
        end;
        output;
    end;
    n=sum(n,1);
    if n&amp;gt;1000 then leave;
    keep i obs switch_in;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 03 Apr 2021 07:36:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-While-Loop-Not-executing/m-p/731111#M227740</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-04-03T07:36:55Z</dc:date>
    </item>
  </channel>
</rss>

