You need to make a new variable to keep the running total so you can RETAIN it.
data input_data;
input Customer_num Total_beds;
cards;
19 60
10 60
25 60
20 60
30 60
15 60
;
data want;
set input_data;
if _n_=1 then new_total=total_beds;
retain new_total;
new_beds=min(customer_num,new_total);
new_total=max(0,new_total-customer_num);
run;
proc print;
run;
Customer_ Total_ new_
Obs num beds total new_beds
1 19 60 41 19
2 10 60 31 10
3 25 60 6 25
4 20 60 0 6
5 30 60 0 0
6 15 60 0 0
... View more