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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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