Close, but your logic is not quite right.
I wrote about this problem in the article, "Use the FLOOR-MOD trick to allocate items to groups."
If you use the function in that article, you get the right answer:
proc iml;
/* See
https://blogs.sas.com/content/iml/2019/04/08/floor-mod-trick-items-to-groups.html
B = total number of items or tasks (B >= 0, scalar)
k = total number of groups or workers (k > 0, scalar)
i = scalar or vector that specifies the group(s), max(i)<=k
Return the number of items to allocate to the i_th group */
start AssignItems(B, k, i);
n = floor(B / k) + (i <= mod(B, k)); /* the FLOOR-MOD trick */
return(n);
finish;
N = 137;
G = 10;
/* split N items among G people? */
idx = T(1:G);
items = AssignItems(N, G, idx);
print items;
total = sum(items); /* did it work? */
print total N;
By the way, notice that you do not need to loop over the number of groups. The FLOOR-MOD trick handles the assignment as a vector operation.