You should be able to do this with retain statement if I understand it correctly.
Just make sure that you do the output before increasing the rank count.
eg:
data test(drop=total);
set dpd;
retain total 0 group 1;
total=total+bucket;
output;
if total>6 then do;
group=group+1;
total=0;
end;
run;
... View more