I feel like this should be simpler. I have N items. I want to distribute them as equally as possible to G people. If G divides N evenly, everyone gets N/G. The following tries to distribute the N=137 items to G=10 peoploe. I want some people to get 14 and some to get 13. PROC IML;
N = 137;
G = 10;
/* split N items among G people? */
maxnum = ceil(N / G);
print maxnum;
items = j(G, 1);
do i = 1 to G;
if N >= maxnum then
items[i] = maxnum;
else
items[i] = maxnum - 1;
N = N - items[i];
end;
print items;
total = sum(items); /* did it work? */
print total N;
QUIT; What am I doing wrong?
... View more