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

标签 sas

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

    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/

相关文章:

sql - 在 proc sql 中为 Case 设置 Null 值

SAS宏: loop to create variables [macro/quoting problem]

excel - 适用于 Microsoft Office 的 SAS 插件 : Excel & Stored Process - don't show external database table in a separate tab

SAS,从数据集列创建文件名

SAS Enterprise Guide - 从本地磁盘读取分隔文件?

java - 将 SAS 日期时间值转换为 Java YYYY-MM-DD HH :mm:ss

sql - 使用 proc 转置计算观察次数

excel - SAS导出到Excel,无法读回SAS

SAS:如何知道哪个宏称为当前宏?

hash - SAS MD5 哈希