hello,
I have patient registry data that is coded wide with ICD-10 diagnosis codes. It has one patient id per row. I'd like to create two dummy variables from all of the wide code, TBI_injury and Spinal_injury. The codes for TBI_injury all start with the prefix: S02.0, S02.1, S02.9, S06.0-S06.6, S06.8, S06.9, S06.A, S07.1 . The Spinal_cord injury start with the prefix: S14, S24, or S34.
Here is just an example of 3 fake patients (bold values represent code prefixs for TBI or spine)
data have;
Studynum: ICD10code_1 ICD10code_2 ICD10code_3
1 S02.028A S00.03XA S06.5X9A
2 S14.5X9A S00.83XA S22.028A
3 S06.5X9A S61.412A S34.5X9A
data want:
Studynum: ICD10code_1 ICD10code_2 ICD10code_3 TBI_injury Spinal_injury
1 S02.028A S00.03XA S06.5X9A 1 0
2 S14.5X9A S00.83XA S22.028A 0 1
3 S06.5X9A S61.412A S34.5X9A 1 1
you may find this paper useful. make an array of the ICD codes and then loop over them.
https://www.sas.com/content/dam/SAS/support/en/sas-global-forum-proceedings/2019/3117-2019.pdf
data example;
input studynum icd10code_1 $ icd10code_2 $ icd10code_3 $;
datalines;
1 S02.028A S00.03XA S06.5X9A
2 S14.5X9A S00.83XA S22.028A
3 S06.5X9A S61.412A S34.5X9A
;
proc print;
run;
data two;
set example;
spinal_injury=0; /*initialize to 0*/;
tbi_injury=0; /*initialize to 0*/;
array diagvar $ icd10code_1-icd10code_3;
do over diagvar;
if diagvar in: ("S14","S24","S34") then spinal_injury=1;
if ("S06.0" <=: diagvar <=: "S06.6") or (diagvar in: ("S02.0","S02.1","S02.9",
"S06.8","S06.9","S06.A","S07.1")) then tbi_injury=1;
end;
proc print;
run;
The above code achieves your desired results.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.