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

hello,

 

can someone please advise how to get Cumulative sum(Running total) of below given data set in Proc SQL...?

 

data a;
input emp$ sal;
cards;
emp1 1000000
emp2 2000000
emp3 3000000
;run;

data b;
input emp$ sal;
cards;
emp1 1000000
emp3 7000000
emp4 4000000
;run;

data c;
merge a b;
by emp;
total+sal;
run;

output should be like below:

--emp--+---sal--+----total--+-

emp1 1000000 1000000
emp2 2000000 3000000
emp3 7000000 10000000
emp4 4000000 14000000

------------------------------------

 

Thanks and Regards,

 

varmalScreenshot (9).png

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

SQL is not very good at processing rows in a given order. For this reason a data step is better suited as mentioned.

View solution in original post

4 REPLIES 4
34reqrwe
Quartz | Level 8

Proc SQL is not a good way to get a cumulative total . You already have the most elegant solution using data step -  why do you need to use Proc SQL?

varmalh
Fluorite | Level 6

I understand you point but there must a simple or complex way of getting the same output..?

34reqrwe
Quartz | Level 8

The simple way is using data step . Yes it can be done using Proc SQL but it is not a good way to tackle the problem . Just like you wouldn't eat soup with a fork . Why do you want to user Proc SQL?

ChrisNZ
Tourmaline | Level 20

SQL is not very good at processing rows in a given order. For this reason a data step is better suited as mentioned.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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