我有三段代码。如何将它们组合成一个以使它们看起来优雅? data1:在某种条件下提取数据; data2:data1左边加入新数据; data3:设置为data2并创建一个新变量。
proc sql; create table data1 as select
a.ID,
b.decison_CD,
c.type,
from
dataA a,
dataB b,
dataC c,
where a.ID=b.ID
and a.ID=c.ID
and c.type not in ('Unknown')
and b.decison_CD in (‘Y’,’N’)
; quit;
proc sql;
create table data2 as select
a.*
,b.payId
from data1 a
left join datanew b
on a.ID=b.ID;
quit;
data data3;
set data2;
if payID= . then booked =0;
else if payID=1 then booked=1;
run;
答案 0 :(得分:0)
看起来您可以使用左连接并将datanew视为第四个数据集:
proc sql;
create table data1 as select
a.ID, b.decison_CD, c.type, d.payId,
case when missing(d.payId) then 0 else
case when d.payID = 1 then 1 end end as booked
from dataA as a
left join dataB (where = (decision_CD in('Y','N'))) as b on a.id = b.id
left join dataC (where = (type notin('Unknown'))) as c on a.id = c.id
left join datanew as d on a.id = d.id;
quit;