I have this table, call it "pre_report":
initial_balance | deposit | withdrawal | final_balance |
---|---|---|---|
1000 | 50 | 0 | . |
1000 | 0 | 25 | . |
1000 | 45 | 0 | . |
1000 | 30 | 0 | . |
1000 | 0 | 70 | . |
I want create a code in SAS that updates the "final_balance" field, the "deposit" field adds to the balance and "withdrawal" subtracts, but at the same time changes the values of the "initial_balance" field, in such a way that my desired output be this:
initial_balance | deposit | withdrawal | final_balance |
---|---|---|---|
1000 | 50 | 0 | 1050 |
1050 | 0 | 25 | 1025 |
1025 | 45 | 0 | 1070 |
1070 | 30 | 0 | 1100 |
1100 | 0 | 70 | 1030 |
I try this:
proc sql;
select initial_balance format=dollar32.2,
deposit format=dollar32.2,
withdrawal format=dollar32.2,
sum(initial_balance,deposit,-withdrawal) as final_balance,
calculated final_balance as initial_balance
from work.pre_report;
quit;
But it doesn't work properly. This code create two fields "final_balance" and "initial_balance" but both with the sames quantity.
code for creating "pre_report" table
data work.pre_report;
input initial_balance deposit withdrawal final_balance;;
datalines;
1000 50 0 .
1000 0 25 .
1000 45 0 .
1000 30 0 .
1000 0 70 .
run;
I would really appreciate if you help me.