【问题标题】:SAS: Patient data on different linesSAS:不同行的患者数据
【发布时间】:2017-03-12 21:00:06
【问题描述】:

我是一名初级 SAS 程序员,我的患者实验室数据位于一行,但他们的诊断数据位于下一行。在进行 FREQ、Logistic、单变量等时,我如何向 SAS 表明他们是同一个患者?我可以在数据步骤中执行此操作吗?

虽然它们位于多行上,但它们具有相同的患者 ID。我想将不同线路上的患者放在同一线路上以进行分析。

patient_id labs disease
1         high
1              celiac
2         low
2              T1DM

谢谢!

【问题讨论】:

  • 很难根据您的问题设想数据。请在您的问题中发布数据样本。
  • 我添加了一个数据样本

标签: sas bioinformatics


【解决方案1】:

假设您正在讲述整个故事 UPDATE。

data; 
   infile cards missover;
   input patient_id (labs disease) ($);
   cards;
1         high
1         .     celiac
2         low
2         .     T1DM
;;;;
   run;
data;
   update _last_(obs=0) _last_;
   by patient_id;
   run; 

【讨论】:

    【解决方案2】:

    这是执行此操作的一种方法(DOW 循环):

    data have;
    input patient_id   labs  $ 11-14 disease  $ 16-21;
    cards;
    1         high
    1              celiac
    2         low
    2              T1DM
    ;
    run;
    
    data want;
    do until(last.patient_id);
        set have;
        by patient_id;
        if labs ne '' then t_labs = labs;
        if disease ne '' then t_disease = disease;
        labs = coalescec(labs,t_labs);
        disease = coalescec(disease,t_disease);
    end;
    drop t_:;
    run;
    

    第二种方式,使用retain语句:

    data want2(drop = t_:);
        set have;
        by patient_id;
        retain t_labs 'xxxx' t_disease 'xxxxxx'; /*Set dummy values so SAS knows these are character variables of appropriate length, or just use a length statement*/
        if first.patient_id then call missing(of t_:);
        if labs ne '' then t_labs = labs;
        if disease ne '' then t_disease = disease;
        labs = coalescec(labs,t_labs);
        disease = coalescec(disease,t_disease);
        if last.patient_id;
    run;
    

    【讨论】:

      猜你喜欢
      • 2016-06-14
      • 2018-03-12
      • 1970-01-01
      • 2018-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-01
      • 2014-07-27
      相关资源
      最近更新 更多