我想添加3列并在下面创建一列是我的代码。如果两列中都有值,则表示b和c我想要d列中的任何值
data a;
infile datalines missover;
input id industry $;
datalines;
1 a
2 b
3
;
run;
data b;
infile datalines missover;
input id industry $;
datalines;
1
2
3 c
;
run;
data c;
infile datalines missover;
input id industry $;
datalines;
1
2
3 d
;
run;
输出应该是
id industry
1 a
2 b
3 c or d (any)
答案 0 :(得分:0)
您可以使用proc sql
:
proc sql;
select id, min(industry)
from ((select id, industry from a
) union all
(select id, industry from b
) union all
(select id, industry from c
)
) abc
group by id;
run;
请注意,这将返回任何表中的任何id。如果表没有相同的id组,这是一种方便的方法。
答案 1 :(得分:0)
您还可以使用coalesce
:
proc sql;
create table temp as select
a.id, coalesce(a.industry, b.industry, c.industry) as industry
from a
left join b
on a.id = b.id
left join c
on a.id = c.id;
quit;