BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
XY7
Fluorite | Level 6 XY7
Fluorite | Level 6

Hi, I am trying to accumulate the total amount by purpose for each bank in this data set, however, I am either only able to obtain the amount based on purpose or bank type itself. Could anyone kindly explain? Thank you.

 

Data:

2019-01-13 (4).png

My codes on the calculation: 

data work.purpose2;
	set work.purpose1;
	by purpose bank_to;
	retain cummulative_value;
	if first.purpose then cummulative_value=amount;
 	else cummulative_value=amount+cummulative_value;
	drop amount;
run; 

Results output:

2019-01-13 (5).png

 

The results are supposed to show something like this (By the bank type and purpose):

bank_to       purpose        cummulative_value

  AB             Leasing              $1234567

  AB             Insurance           $1234567

  AB            Household          $1234567

  GH            Insurance           $1234567

....

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
PROC MEANS DATA=have nway NOPRINT;
class bank_to purpose;
VAR amount;
OUTPUT OUT=want SUM=cumulative_value;
RUN; 

View solution in original post

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

And yoy want to do this in a data step? Or are you allowed to use a procedure like PROC SUMMARY?

XY7
Fluorite | Level 6 XY7
Fluorite | Level 6

Yes, I am allowed to do so.

novinosrin
Tourmaline | Level 20
PROC MEANS DATA=have nway NOPRINT;
class bank_to purpose;
VAR amount;
OUTPUT OUT=want SUM=cumulative_value;
RUN; 
XY7
Fluorite | Level 6 XY7
Fluorite | Level 6

Thank you very much!