Hello,
i have dataset with member id along with diagnosis codes, that needs to be bumped against certain icd10 code list.
If there a match found, i just want to output the matched code into new column.
How do i achieve it.
below is the sample data.
member dataset
Memberid | Diagnosis |
8001 | R413 E039 H900 NA |
8002 | I10 R9431 R4181 Z23 E119 |
8003 | G9341 R4189 G4701 I639 NA |
8004 | I2699 R413 E119 E782 E039 |
8005 | G4752 F0390 Z6828 R296 R2681 R413 G609 I672 NA |
8006 | I63511 I10 Z6822 G3184 K3184 R4182 R4181 E538 L988 I69354 F0390 E119 |
8007 | M79641 R29898 E1142 R41841 I130 |
8008 | B348 G309 F0280 J449 NA F0390 R1312 R2689 F419 F329 E039 I10 J209 J329 R5081 |
icd10 dataset;
ICD9_10 |
R413 |
R4931 |
E119 |
E782 |
F0390 |
L988 |
I130 |
F329 |
Expected Output;
Memberid | Diagnosis | Match1 | Match2 | Match3 |
8001 | R413 E039 H900 NA | R413 | ||
8002 | I10 R9431 R4181 Z23 E119 | E119 | ||
8003 | G9341 R4189 G4701 I639 NA | |||
8004 | I2699 R413 E119 E782 E039 | R413 | E119 | |
8005 | G4752 F0390 Z6828 R296 R2681 R413 G609 I672 NA | R413 | ||
8006 | I63511 I10 Z6822 G3184 K3184 R4182 R4181 E538 L988 I69354 F0390 E119 | E119 | F0390 | L988 |
8007 | M79641 R29898 E1142 R41841 I130 | I130 | ||
8008 | B348 G309 F0280 J449 NA F0390 R1312 R2689 F419 F329 E039 I10 J209 J329 R5081 | F0390 | F329 |
data have;
infile cards expandtabs truncover;
input Memberid Diagnosis & $80.;
cards;
8001 R413 E039 H900 NA
8002 I10 R9431 R4181 Z23 E119
8003 G9341 R4189 G4701 I639 NA
8004 I2699 R413 E119 E782 E039
8005 G4752 F0390 Z6828 R296 R2681 R413 G609 I672 NA
8006 I63511 I10 Z6822 G3184 K3184 R4182 R4181 E538 L988 I69354 F0390 E119
8007 M79641 R29898 E1142 R41841 I130
8008 B348 G309 F0280 J449 NA F0390 R1312 R2689 F419 F329 E039 I10 J209 J329 R5081
;
data icd10;
input ICD9_10 $;
cards;
R413
R4931
E119
E782
F0390
L988
I130
F329
;
data temp;
if _n_=1 then do;
if 0 then set icd10;
declare hash h(dataset:'icd10');
h.definekey('icd9_10');
h.definedone();
end;
set have;
found=0;
do i=1 to countw(Diagnosis,' ');
temp=scan(Diagnosis,i,' ');
if h.check(key:temp)=0 then do;found=1;var=temp;output;end;
end;
if not found then output;
drop i found temp;
run;
proc transpose data=temp out=want prefix=match;
by memberid Diagnosis;
var var;
run;
Is the order of the values in the ICD10 data set important in this problem?
I ask because for Memberid = 8004 the match variables are in the order as they appear from left to right in that Diagnosis varible. But for Memberid = 8006 the right most match is reported in the first match position (actually in reverse of their appearance in the diagnosis variable for all three).
What is the maximum number of diagnosis codes that appears in any record? Since potentially all of the codes could be matches then you need that many match variables.
What do you want to do if the same diagnosis code appears twice or more times for the same memberid? (or have you even looked).
Is that an exhaustive list of ICD10 codes or are there more?
data have;
infile cards expandtabs truncover;
input Memberid Diagnosis & $80.;
cards;
8001 R413 E039 H900 NA
8002 I10 R9431 R4181 Z23 E119
8003 G9341 R4189 G4701 I639 NA
8004 I2699 R413 E119 E782 E039
8005 G4752 F0390 Z6828 R296 R2681 R413 G609 I672 NA
8006 I63511 I10 Z6822 G3184 K3184 R4182 R4181 E538 L988 I69354 F0390 E119
8007 M79641 R29898 E1142 R41841 I130
8008 B348 G309 F0280 J449 NA F0390 R1312 R2689 F419 F329 E039 I10 J209 J329 R5081
;
data icd10;
input ICD9_10 $;
cards;
R413
R4931
E119
E782
F0390
L988
I130
F329
;
data temp;
if _n_=1 then do;
if 0 then set icd10;
declare hash h(dataset:'icd10');
h.definekey('icd9_10');
h.definedone();
end;
set have;
found=0;
do i=1 to countw(Diagnosis,' ');
temp=scan(Diagnosis,i,' ');
if h.check(key:temp)=0 then do;found=1;var=temp;output;end;
end;
if not found then output;
drop i found temp;
run;
proc transpose data=temp out=want prefix=match;
by memberid Diagnosis;
var var;
run;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.