proc sql 与不同变量的联合

proc sql union with different variables

我正在尝试使用 proc sql - union 连接两个 table,其中某些变量对于每个 table 都是唯一的。有没有办法不使用 NULL 占位符变量来做到这一点?基本上相当于下面的数据步骤。

data total;
set t1 t2;
run;

下面显示了我正在尝试做的一个简单示例。

data animal;
input common $ Animal $ Number;
    datalines;
a Ant 5
b Bird .
c Cat 17
d Dog 9
e Eagle .
f Frog 76
;
run;


data plant;
input Common $ Plant $ Number;
    datalines;
g Grape 69
h Hazelnut 55
i Indigo .
j Jicama 14
k Kale 4
l Lentil 88
;
run;

proc sql;
(select animal.*, '' as plant from animal)
union all corresponding
(select plant.*, '' as animal from plant)
;
quit;

我希望能够 运行 proc sql 而不必在 select 语句中创建 plantanimal 变量。

你想要 outer union,而不是 union all。这符合您的预期(将所有变量保留在任一数据集中)。有关详细信息,请参阅 Howard Schreier's excellent paper on SQL set theory

proc sql;
create table test as
select * from animal
outer union corr
select * from plant
;
quit;