我有一个数据集,其中患者的某些变量可能有多个(未知)值,最终看起来像这样:
ID Var1 Var2 Var3 Var4
1 Blue Female 17 908
1 Blue Female 17 909
1 Red Female 17 910
1 Red Female 17 911
...
99 Blue Female 14 908
100 Red Male 28 911
我想将这些数据打包,以便每个 ID 只有一个条目,并带有指示其原始条目系列中是否存在其中一个值的指示符。因此,例如,像这样的事情:
ID YesBlue Var2 Var3 Yes911
1 1 Female 17 1
99 1 Female 14 0
100 0 Male 28 1
在 SAS 中是否有直接的方法来执行此操作?或者在 Access(数据的来源)中失败,我真的不知道如何使用。
最佳答案
如果你的数据集叫做 PATIENTS1,可能是这样的:
proc sql noprint;
create table patients2 as
select *
,case(var1)
when "Blue" then 1
else 0
end as ablue
,case(var4)
when 911 then 1
else 0
end as a911
,max(calculated ablue) as yesblue
,max(calculated a911) as yes911
from patients1
group by id
order by id;
quit;
proc sort data=patients2 out=patients3(drop=var1 var4 ablue a911) nodupkey;
by id;
run;
关于sas - 在 SAS 中展平多个观测值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14230948/