<?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 Do While Loop for Allocating Remainder of Macro Variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Do-While-Loop-for-Allocating-Remainder-of-Macro-Variable/m-p/566993#M159412</link>
    <description>&lt;P&gt;I am coding a distribution of flu vaccine. I allocate this vaccine to individual providers based on what they've ordered via various steps (for example, step 1 is allocating 10 doses of vaccine to providers who ordered &amp;lt; 500; step 2 is allocating 50 doses of vaccine to providers who ordered &amp;gt;= 500, etc).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have reached the end of my distribution and am left with a macro variable that is the remainder of doses (in this case, 160). I have updated each provider order based on steps 1-5 on the amount of vaccine I've already distributed and have an order_remaining - some provider orders have been completed (order_remaining = 0) and some provider orders are still in need of additional doses (order_remaining = 50). I've included a screenshot of part of my dataset below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to distribute the remainder (160 doses) to fulfill the lowest remaining orders while the remainder &amp;gt; 0 in step 6.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My thought was to use a do-while loop like:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;

set vaccine_distribution;

remainder = &amp;amp;remainder;

do while (remainder &amp;gt; 0);

step_6 = order_remaining;

remainder + (-step_6);

end;

run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want the code to distribute vaccine to the lowest volume of order_remaining in multiples of 10 while the remainder &amp;gt; 0. In the screenshot I've included and based on a remainder of 160, I would expect the orders of 30 and one of the orders of 50 to be completed with 40 vaccines remaining (i.e. 30, 30, 30, 50).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can't find any examples online of using a do while loop with the condition decreasing (i.e. remainder is going down each loop) rather than increasing and can't get the above code to complete.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help!&lt;/P&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>Tue, 18 Jun 2019 19:08:33 GMT</pubDate>
    <dc:creator>jblogan</dc:creator>
    <dc:date>2019-06-18T19:08:33Z</dc:date>
    <item>
      <title>Do While Loop for Allocating Remainder of Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-While-Loop-for-Allocating-Remainder-of-Macro-Variable/m-p/566993#M159412</link>
      <description>&lt;P&gt;I am coding a distribution of flu vaccine. I allocate this vaccine to individual providers based on what they've ordered via various steps (for example, step 1 is allocating 10 doses of vaccine to providers who ordered &amp;lt; 500; step 2 is allocating 50 doses of vaccine to providers who ordered &amp;gt;= 500, etc).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have reached the end of my distribution and am left with a macro variable that is the remainder of doses (in this case, 160). I have updated each provider order based on steps 1-5 on the amount of vaccine I've already distributed and have an order_remaining - some provider orders have been completed (order_remaining = 0) and some provider orders are still in need of additional doses (order_remaining = 50). I've included a screenshot of part of my dataset below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to distribute the remainder (160 doses) to fulfill the lowest remaining orders while the remainder &amp;gt; 0 in step 6.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My thought was to use a do-while loop like:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;

set vaccine_distribution;

remainder = &amp;amp;remainder;

do while (remainder &amp;gt; 0);

step_6 = order_remaining;

remainder + (-step_6);

end;

run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want the code to distribute vaccine to the lowest volume of order_remaining in multiples of 10 while the remainder &amp;gt; 0. In the screenshot I've included and based on a remainder of 160, I would expect the orders of 30 and one of the orders of 50 to be completed with 40 vaccines remaining (i.e. 30, 30, 30, 50).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can't find any examples online of using a do while loop with the condition decreasing (i.e. remainder is going down each loop) rather than increasing and can't get the above code to complete.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help!&lt;/P&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>Tue, 18 Jun 2019 19:08:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-While-Loop-for-Allocating-Remainder-of-Macro-Variable/m-p/566993#M159412</guid>
      <dc:creator>jblogan</dc:creator>
      <dc:date>2019-06-18T19:08:33Z</dc:date>
    </item>
    <item>
      <title>Re: Do While Loop for Allocating Remainder of Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-While-Loop-for-Allocating-Remainder-of-Macro-Variable/m-p/567012#M159413</link>
      <description>Please post some sample data as TEXT not PDF or an attachment, and include what you want as the output. This should be relatively easy using a DO loop with a BY option to decrease it as you go.</description>
      <pubDate>Tue, 18 Jun 2019 18:55:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-While-Loop-for-Allocating-Remainder-of-Macro-Variable/m-p/567012#M159413</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-06-18T18:55:54Z</dc:date>
    </item>
    <item>
      <title>Re: Do While Loop for Allocating Remainder of Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-While-Loop-for-Allocating-Remainder-of-Macro-Variable/m-p/567019#M159414</link>
      <description>&lt;P&gt;Remainder = 160.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So this is an example of the current dataset:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;Order_Amount&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;Step_1&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;Step_2&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;Step_3&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;Amount_Allocated&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;Order_Remaining&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;100&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;10&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;90&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;0&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;100&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;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TD&gt;&lt;TD&gt;&lt;P&gt;140&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;150&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;50&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;50&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;800&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;50&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;0&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;250&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;300&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;500&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;50&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;800&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;50&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;0&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;250&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;300&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;500&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;0&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Step_6 would revert to 0 when the remainder = 0 because all 160 doses were allotted to earlier orders.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jun 2019 19:08:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-While-Loop-for-Allocating-Remainder-of-Macro-Variable/m-p/567019#M159414</guid>
      <dc:creator>jblogan</dc:creator>
      <dc:date>2019-06-18T19:08:08Z</dc:date>
    </item>
  </channel>
</rss>

