Prev: PROC GREPLAY and BY lists
Next: Join data horizontally
From: Dave on 11 Feb 2010 05:45 I am looking to this group for suggestions to improve or suggest a better way to come up with a solution to my problem. Background: I have one record per icd9 code per patient id. I have a list of 50 icd9 codes that I need to see if the patient ever was diagnosed with that code by creating a new variable (0=no, 1=yes) for each wanted code. Output only one record per patient id containing only those new 0/1 variables and id. Example (for sake of brevity, I am only looking for 3 specific icd9 codes, but in the real run I will be looking for 50): I am searching the records for icd9 code = 49300, 49301 and 49302 (icd9 is a character variable). Create another new variable "exclusion" if we found any of the specific icd9 codes. Output only one record per patient id. data have; length id icd9 $5 ; input id $ icd9 $; cards; 1 33333 1 22 1 49300 2 356 2 123 3 49321 4 49300 4 49301 4 49302 ; run; data want; set have; by id; retain dx49300 dx49301 dx49302 0; if first.id then do; dx49300 = 0; dx49301 = 0; dx49302 = 0; end; if icd9 = '49300' then dx49300 = 1 ; else if icd9 = '49301' then dx49301 = 1 ; else if icd9 = '49302' then dx49302 = 1 ; if sum(of dx49300 dx49301 dx49302) > 0 then exclusion = 1; else exclusion = 0; drop icd9; if last.id then output; run; proc print data=want noobs; run; As you can see, this can get quite tedious when I need to check for 50 codes. What is a better, more efficient way of solving my problem? Thanks much. Dave
|
Pages: 1 Prev: PROC GREPLAY and BY lists Next: Join data horizontally |