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

I have several tables

 

Table1:

Var1

A

B

C

D

E

F

G

 

Table 2:

Var2

A

D

F

G

 

Table 3:

Var3

C

D

F

G

 

i want to get these into a single table in the form of

 

Var1     Var2     Var3

A             A

B                         B

C                         C

D            D          D

E

F            F           F

G           G          G

 

any suggestions?

1 ACCEPTED SOLUTION

Accepted Solutions
mklangley
Lapis Lazuli | Level 10
proc sql;
    create table want as
    select *
    from table1 a
    full join table2 b on a.var1 = b.var2
    full join table3 c on a.var1 = c.var3
    ;
run;

View solution in original post

5 REPLIES 5
mklangley
Lapis Lazuli | Level 10
proc sql;
    create table want as
    select *
    from table1 a
    full join table2 b on a.var1 = b.var2
    full join table3 c on a.var1 = c.var3
    ;
run;
mcook
Quartz | Level 8
I have been trying full joins, but it is not working as I expect.
mklangley
Lapis Lazuli | Level 10

What do you mean by "it is not working"?  Can you include your data and code, and the results you are seeing?

mcook
Quartz | Level 8
Thanks. Full join did finally work. I just had a minor syntax error that i had overlooked.
andreas_lds
Jade | Level 19

Could be solved with a merge, if you don't mind creating a common key-variable in all dataset:

data Table1;
   input Var1 $;
   key = Var1;

   datalines;
A
B
C
D
E
F
G
;
run;
 

data Table2;
   input Var2 $;
   key = Var2;

   datalines;
A
D
F
G
;
run;
 

data Table3;
   input Var3 $;
   key = Var3;

   datalines;
B 
C
D
F
G
;
run;

data all;
   merge Table1 Table2 Table3;
   by key;

   drop Key;
run;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 5 replies
  • 586 views
  • 1 like
  • 3 in conversation