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,
varmal
SQL is not very good at processing rows in a given order. For this reason a data step is better suited as mentioned.
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?
I understand you point but there must a simple or complex way of getting the same output..?
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?
SQL is not very good at processing rows in a given order. For this reason a data step is better suited as mentioned.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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: