Reputation: 147
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!
Upvotes: 0
Views: 66
Reputation: 9109
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;
Upvotes: 2
Reputation: 9569
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;
Upvotes: 0