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!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 1267 views
  • 0 likes
  • 3 in conversation