Desktop productivity for business analysts and programmers

Sum data from different tables

Accepted Solution Solved
Reply
Contributor
Posts: 30
Accepted Solution

Sum data from different tables

i have two tables in sas ed which have the same columns and I need to sum variable 

table 1: 

Id      Name       count 

1        A                20

2        B                45

3        C               56

4        D                10

 

table 2 : 

Id      Name       count 

1        A                7

2        B                15

3        C               75

4        D                80

 

output i want: 

 

Id      Name       count 

1        A                27

2        B                60

3        C               131

4        D                90


Accepted Solutions
Solution
‎03-14-2018 07:30 PM
Super User
Posts: 22,874

Re: Sum data from different tables

Append the tables and use proc means?

Note that this creates a view which means the table doesn't really exist but is just used for the calculation.  If you want a real combined table delete the view portion.

 

data combined / view=combined;
set table1 table2;
run;

proc means data=combined nway;
class name;
var count;
run;

@hk2013 wrote:

i have two tables in sas ed which have the same columns and I need to sum variable 

table 1: 

Id      Name       count 

1        A                20

2        B                45

3        C               56

4        D                10

 

table 2 : 

Id      Name       count 

1        A                7

2        B                15

3        C               75

4        D                80

 

output i want: 

 

Id      Name       count 

1        A                27

2        B                60

3        C               131

4        D                90


 

View solution in original post


All Replies
Solution
‎03-14-2018 07:30 PM
Super User
Posts: 22,874

Re: Sum data from different tables

Append the tables and use proc means?

Note that this creates a view which means the table doesn't really exist but is just used for the calculation.  If you want a real combined table delete the view portion.

 

data combined / view=combined;
set table1 table2;
run;

proc means data=combined nway;
class name;
var count;
run;

@hk2013 wrote:

i have two tables in sas ed which have the same columns and I need to sum variable 

table 1: 

Id      Name       count 

1        A                20

2        B                45

3        C               56

4        D                10

 

table 2 : 

Id      Name       count 

1        A                7

2        B                15

3        C               75

4        D                80

 

output i want: 

 

Id      Name       count 

1        A                27

2        B                60

3        C               131

4        D                90


 

Super User
Posts: 22,874

Re: Sum data from different tables

If you're using the GUI then you should use the Append Task to combine the data and then a query or summarize task. 

Not sure if you can do unions via the query builder, if you can that's another viable approach.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 145 views
  • 0 likes
  • 2 in conversation