Hello Everyone , I have This DataSet :
User | SPENDING |
User_1 | 50,32$ |
User_1 | 250,36$ |
User_1 | 322,2$ |
User_1 | 222,2$ |
User_2 | 30,2$ |
User_2 | 563$ |
User_2 | 24,23$ |
User_2 | 210,32$ |
And What I Want To Do , is to make an iterative sum for each user ,i.e:
like for user_1 i want , for the first line , the first spending , for the second column , i want , to sum of spending between line 1 and line 2 , for the third column , i want the sum of spending in line1 , line2 , line 3 .....ect , like my output would look like this :
User | SPENDING | Total |
User_1 | 50,32$ | 50,32$ |
User_1 | 250,36$ | 300,68$ |
User_1 | 322,2$ | 622,88$ |
User_1 | 222,2$ | 845,08$ |
User_2 | 30,2$ | 30,2$ |
User_2 | 563$ | 593,2$ |
User_2 | 24,23$ | 617,43$ |
User_2 | 210,32$ | 827,75$ |
Any suggestions on how to do that , would be much appreciated , thank you.
Do like this
data have;
input User $ SPENDING commax10.;
datalines;
User_1 50,32$
User_1 250,36$
User_1 322,2$
User_1 222,2$
User_2 30,2$
User_2 563$
User_2 24,23$
User_2 210,32$
;
data want;
set have;
by User;
if first.User then Total=0;
Total+SPENDING;
format SPENDING Total dollar10.2;
run;
Result:
User SPENDING Total User_1 $50.32 $50.32 User_1 $250.36 $300.68 User_1 $322.20 $622.88 User_1 $222.20 $845.08 User_2 $30.20 $30.20 User_2 $563.00 $593.20 User_2 $24.23 $617.43 User_2 $210.32 $827.75
Do like this
data have;
input User $ SPENDING commax10.;
datalines;
User_1 50,32$
User_1 250,36$
User_1 322,2$
User_1 222,2$
User_2 30,2$
User_2 563$
User_2 24,23$
User_2 210,32$
;
data want;
set have;
by User;
if first.User then Total=0;
Total+SPENDING;
format SPENDING Total dollar10.2;
run;
Result:
User SPENDING Total User_1 $50.32 $50.32 User_1 $250.36 $300.68 User_1 $322.20 $622.88 User_1 $222.20 $845.08 User_2 $30.20 $30.20 User_2 $563.00 $593.20 User_2 $24.23 $617.43 User_2 $210.32 $827.75
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: