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

时间:2017-03-12 21:00:06

标签: sas bioinformatics

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

虽然它们在多行上,但它们具有相同的patient_ID。我想把不同行的患者放在同一条线上进行分析。

patient_id labs disease
1         high
1              celiac
2         low
2              T1DM

谢谢!

2 个答案:

答案 0 :(得分:2)

假设你告诉整个故事更新。

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; 

答案 1 :(得分:0)

这是一种方法(DOW-loop):

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;