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 < 500; step 2 is allocating 50 doses of vaccine to providers who ordered >= 500, etc).
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.
I would like to distribute the remainder (160 doses) to fulfill the lowest remaining orders while the remainder > 0 in step 6.
My thought was to use a do-while loop like:
data test;
set vaccine_distribution;
remainder = &remainder;
do while (remainder > 0);
step_6 = order_remaining;
remainder + (-step_6);
end;
run;
I want the code to distribute vaccine to the lowest volume of order_remaining in multiples of 10 while the remainder > 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).
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.
Thanks for your help!
Remainder = 160.
So this is an example of the current dataset:
Order_Amount | Step_1 | Step_2 | Step_3 | Amount_Allocated | Order_Remaining |
100 | 10 | 90 | 0 | 100 | 0 |
120 | 10 | 0 | 80 | 90 | 30 |
150 | 10 | 0 | 110 | 120 | 30 |
200 | 10 | 0 | 140 | 150 | 50 |
800 | 50 | 0 | 250 | 300 | 500 |
800 | 50 | 0 | 250 | 300 | 500 |
Desired Output:
Order_Amount | Step_1 | Step_2 | Step_3 | Amount_Allocated | Order_Remaining | Step_6 |
100 | 10 | 90 | 0 | 100 | 0 | 0 |
120 | 10 | 0 | 80 | 90 | 30 | 30 |
150 | 10 | 0 | 110 | 120 | 30 | 30 |
200 | 10 | 0 | 140 | 150 | 50 | 50 |
800 | 50 | 0 | 250 | 300 | 500 | 50 |
800 | 50 | 0 | 250 | 300 | 500 | 0 |
Step_6 would revert to 0 when the remainder = 0 because all 160 doses were allotted to earlier orders.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.