BookmarkSubscribeRSS Feed
jblogan
Calcite | Level 5

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!

 

 

 

2 REPLIES 2
Reeza
Super User
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.
jblogan
Calcite | Level 5

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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 925 views
  • 0 likes
  • 2 in conversation