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

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

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
  • 4865 views
  • 0 likes
  • 3 in conversation