Sorry I don't understand what you are looking for, I wrote the code below but this does not result in what you have. Can you explain a bit more. Do you mean the sum of all the previous values, all the values since the rank was incremented, the last two values?
data ranked;
retain rank 1 sum_vals;
set dpd;
sum_vals+bucket;
if sum_vals>6 then do;
rank+1;
sum_vals=0;
end;
run;
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;