SAS:不同线路上的患者数据

SAS: Patient data on different lines

我是一名初级 SAS 程序员,我的病人实验室数据在一行,但他们的诊断数据在下一行。在执行 FREQ、Logistic、Univariate 等时如何向 SAS 表明他们是同一个患者?我可以在数据步骤中这样做吗?

虽然分在多行,但是一样patient_ID。我想把不同线路的病人放在同一条线路上进行分析。

patient_id labs disease
1         high
1              celiac
2         low
2              T1DM

谢谢!

这是一种方法(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;

第二种方式,使用保留语句:

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;

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

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;