gpt4 book ai didi

sas - 在 SAS 中展平多个观测值

转载 作者:行者123 更新时间:2023-12-04 18:20:12 27 4
gpt4 key购买 nike

我有一个数据集,其中患者的某些变量可能有多个(未知)值,最终看起来像这样:

    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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com