Hospitalized patients can have a diagnosis coded in their medical record in one of two ways: as an APRDRG or an MSDRG. These are stored in two look-up tables “APR” and ‘MS”. * Tables apr and ms;
data apr; input diagnosis $21. aprdrg $3.;
cards;
Heart_Failure 001
Myocardial_Infarction 002
Stroke 103
Respiratory_Failure
GI_Bleeding 116
GI_Cancer 167
GI_Obstruction 172
Influenza 298
Head_Trauma 300
;
run;
data ms; input diagnosis $21. msdrg $3.;
cards;
Heart_Failure 001
Myocardial_Infarction 005
Stroke 098
Respiratory_Failure 103
GI_Bleeding 112
GI_Cancer
Asthma 174
Influenza 298
Head_Trauma 300
Pelvic_Fractue 302
;
run; I also have a table of patients called "MAIN", in which patients have an ID, code, and drg_type to let you know that the diagnosis should be taken from the corresponding table (apr or ms). /* Sometimes the diagnosis for an aprdrg is the same as that for an msdrg
But most of the time it isn't. A few diagnoses appear in one table but
not the other. Both tables have diagnoses with missing aprdrg or msdrg. */
* Table MAIN with PTID (patient ID), code(string that matches up with APRDRG & MSDRG values).;
data main; input @1 ptid $3. @5 code $3. @9 drg_type $1.;
cards;
111 002 A
112 103 A
113 112 A
114 298 A
115 300 A
116 005 M
117 103 M
118 112 M
119 167 M
120 222 M
;
run; What I want is to get a final table that contains each patient and their correct diagnosis. It would be easy if the APR and MS DRG codes were distinct. But some diagnoses have both an APRDRG and an MSDRG code, and they could be different. The way around it for each patient is to determine if the drg_type is A then see if code matches up with an APRDRG code. If so, then grab the corresponding diagnosis from the APR table. If not, then use the MS table. If neither work, then leave a blank for diagnosis. The same goes if a code is M. Look first in the MS table, then the APR table, if no match then use the MS table, and finally leave a blank if neither matches up. The final table looks like this: * drg_type in rthis table indicates which look-up table provided the diagnosis.
data final; input PatientID $3. drg_type $1. code $3.Diagnosis $21.;
cards;
111 A 002 Myocardial_Infarction
112 A 103 Stroke
113 M 112 GI_Bleeding
114 A 298 Influenza
115 A 300 Head_Trauma
116 M 005 Myocardial_Infarction
117 M 103 Respiratory_Failure
118 M 112 GI_Bleeding
119 A 167 GI_Cancer
120 '' 222 ''
; I'm uncertain how to do this, so any help would be much appreciated. Thanks!
... View more