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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

2 REPLIES 2
Reeza
Super User

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


 

Reeza
Super User

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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 2 replies
  • 4111 views
  • 0 likes
  • 2 in conversation