これは、SQL が通常の SAS ほど得意とすることではありませんが、確かに可能です。
いくつかのオプション:
COALESCE を使用した外部結合。最初の選択で各変数を2回書き出す必要があるため、他のオプションよりも書きにくい。
proc sql;
select coalesce(s1.id,s2.id) as id, coalescec(s1.race,s2.race) as race from (
(select * from sample2) s2
full outer join
(select *,"1" as sample1 from sample1) s1
on s2.id=s1.id);
quit;
EXISTS サブクエリと結合します。テーブルのサイズによっては遅くなります。これが 10 行テーブルと組み合わされた 10k テーブルである場合、これは高速なソリューションです。2 つの 10k テーブルの場合、これは低速です。
proc sql;
select * from sample1
union
select * from sample2 where not exists (
select 1 from sample1 where sample1.id=sample2.id
);
quit;
JOIN で結合します。インデックス作成などによっては、上記のクエリよりも高速になる場合があります。
proc sql;
select * from sample1
union
select sample2.* from sample2
left join sample1
on sample1.id=sample2.id
where missing(sample1.id);
quit;
しかし、SAS で最も簡単な解決策は、間違いなく SAS でそれを行うことです。
data sample12_view/view=sample12_view;
set sample1 sample2;
run;
proc sort nodupkey data=sample12_view out=sample12;
by id;
run;
また
data sample12;
merge sample1(in=s1) sample2(in=s2);
by id;
run;
その場合、s2 は s1 を置き換えるので、他のオプションを好む場合は、merge ステートメントの順序を変更してください。