0
votes

I am a beginning SAS programmer, and I have patient lab data that is on one line, but their diagnosis data is on the next line. How do I indicate to SAS when doing FREQ, Logistic, Univariate, etc. that they are the same patient? Can I do this in the data step?

Although they are on multiple lines, they have the same patient_ID. I would like to put the patient that is on different lines, onto the same line for analysis purposes.

patient_id labs disease
1         high
1              celiac
2         low
2              T1DM

Thanks!

2
It's hard to envision the data based on your question. Please post a sample of the data in your question.mjsqu
I added a sample of the dataybao

2 Answers

2
votes

Assuming you're telling the whole story 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; 
0
votes

Here is one way of doing this (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;

And a second way, using a retain statement:

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;