I have several tables
Table1:
Var1
A
B
C
D
E
F
G
Table 2:
Var2
A
D
F
G
Table 3:
Var3
B
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?
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;
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;
What do you mean by "it is not working"? Can you include your data and code, and the results you are seeing?
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;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.