Hi.
I have two identical tables and I want to add the last column of the second table to the first table. But I want to change the variable names.
How do I program it?
Table 1
| Group | Setting | Value |
| 1 | a | 25 |
| 2 | b | 30 |
| 3 | c | 45 |
Table 2
| Group | Setting | Value |
| 1 | a | 48 |
| 2 | b | 59 |
| 3 | c | 35 |
Final output
| Group | Setting | Value 1 | Value 2 |
| 1 | a | 25 | 48 |
| 2 | b | 30 | 59 |
| 3 | c | 45 | 35 |
Thanks.
proc sql;
create table want as
select
coalesce(t1.group,t2.group) as group,
coalesce(t1.setting,t2.setting) as setting,
t1.value as value_1,
t2.value as value_2
from table1 t1
full join table2 t2
on t1.group = t2.group and t1.setting = t2.setting
;
quit;
data want;
merge
table1 (rename=(value=value_1))
table2 (rename=(value=value_2))
;
by group setting;
run;
proc sql;
create table want as
select
coalesce(t1.group,t2.group) as group,
coalesce(t1.setting,t2.setting) as setting,
t1.value as value_1,
t2.value as value_2
from table1 t1
full join table2 t2
on t1.group = t2.group and t1.setting = t2.setting
;
quit;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.