BookmarkSubscribeRSS Feed
stancemcgraw
Obsidian | Level 7

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

1 REPLY 1
tarheel13
Rhodochrosite | Level 12

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. 

tarheel13_1-1670978573273.png

 

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 900 views
  • 2 likes
  • 2 in conversation