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?
retain rank 1 sum_vals;
if sum_vals>6 then do;