Help using Base SAS procedures

How to combine tables

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 17
Accepted Solution

How to combine tables

TABLE 1.

Student | Math | English | Science

Sue           3.5        6.0          2.1

Amy          3.7        5.3          2.8

Cindy        2.9        5.8          3.5

Kevin        3.2        6.2          2.1

 

TABLE 2.

Math National Avg | English National Avg | Science National Avg

                       3.6                             6.1                               3.8

 

TABLE WANT

Student | Math | English | Science | Math National Avg | English National Avg | Science National Avg

Sue           3.5        6.0          2.1                            3.6                              6.1                              3.8

Amy          3.7        5.3          2.8                            3.6                              6.1                              3.8

Cindy        2.9        5.8          3.5                            3.6                              6.1                              3.8

Kevin        3.2        6.2          2.1                            3.6                              6.1                              3.8

 

I want to combine table 1 and table 2 to create table want. I don't know how to combine tables without an unique idenitifier. Someone please help. 

 


Accepted Solutions
Solution
‎04-18-2016 12:18 PM
Super User
Posts: 17,868

Re: How to combine tables

Data want;
If _n_ = 1 then set table2;

Set table1;

Run;

Try this. 

View solution in original post


All Replies
Super User
Super User
Posts: 7,408

Re: How to combine tables

Something like this (not tested - for tested code post test data in the form of a datastep):

data want;
  merge table1 table2;
run;
Occasional Contributor
Posts: 17

Re: How to combine tables

I already tried this, and it didn't work. It came out like this:

Student | Math | English | Science | Math National Avg | English National Avg | Science National Avg

Sue           3.5        6.0          2.1                           

Amy          3.7        5.3          2.8                          

Cindy        2.9        5.8          3.5                         

Kevin        3.2        6.2          2.1                           

                                                                                3.6                              6.1                              3.8

Solution
‎04-18-2016 12:18 PM
Super User
Posts: 17,868

Re: How to combine tables

Data want;
If _n_ = 1 then set table2;

Set table1;

Run;

Try this. 

Super User
Super User
Posts: 7,408

Re: How to combine tables

This shold work:

data a;
  a=1; output;
  a=2; output;
run;
data b;
  c=1;
run;
proc sql;
  create table WANT as
  select *
  from   A
  full join B
  on     1=1;
quit;
☑ This topic is SOLVED.

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

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