我使用下面的代码,但在最终输出中,我无法在收入为234234的第一个条目中获取名称。如何在此输入名称。
data names;
input name $ age;
datalines;
John 10
Mary 12
Sally 12
Fred 1
Paul 2
;
run;
data check;
input name $ income;
datalines;
Mary 121212
Fred 334343
Ben 234234
;
Proc sql;
title 'Inner Join';
create table common_names as
select * from names as n right join check as c on
n.name = c.name;
run;
Proc print data = common_names;
run;
Output
Inner Join
Obs name age income
1 . 234234
2 Fred 1 334343
3 Mary 12 121212
答案 0 :(得分:3)
您不能创建两个具有相同名称的变量,在本例中为变量NAME。所以要么创建两个变量
select n.name as name1, c.name as name2, ....
或使用COALESCE()
函数创建单个变量。
select coalesce(n.name,c.name) as name, ....
您还可以查看SAS NATURAL
加入的内容。这将链接具有相同名称的变量表,并自动合并键变量值。
create table common_names as
select *
from names as n
natural right join check as c
;