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 get the data to be longways so that I can easily parse out the codes that I need. 

The codes go all the way to 41 (ICD10code_41) and they might not always be filled in all the way to 41. (or am looking for another way to create two dummy variables, spinal injury and TBI injury, based on specific ICD_10 codes I have for this study from this wide data).

 

Here is just an example of 3 fake patients:

data have;

Studynum:  ICD10code_1   ICD10code_2  ICD10code_3  ICD10code_4

1                      S22.028A    S00.03XA          S06.5X9A

2                      S06.5X9A     S00.83XA         S22.028A 

3                       S06.5X9A     S61.412A        S06.5X9A          S06.6X9A

data want;

Studynum     ICD_code

1                   S22.028A

1                   S00.03XA

1                   S06.5X9A

2                   S06.5X9A 

2                   S00.83XA  

2                    S22.028A

3                   S06.5X9A  

3                  S61.412A

3                  S06.5X9A

3                  S06.6X9A

2 REPLIES 2
PaigeMiller
Diamond | Level 26
data want;
    set have;
    length icd_code $ 8;
    array icd10 ic10code_:;
    do i=1 to dim(icd10);
         if not missing(icd10(i)) then icd_code=icd10(i);
         output;
    end;
    keep icd_code studynum;
run;
--
Paige Miller
Kurt_Bremser
Super User

Try PROC TRANSPOSE:

proc transpose
  data=have
  out=want (
    drop=_name_ 
    rename=(col1=icd_code)
    where=(icd_code ne "")
  )
;
by studynum;
var icd:;
run;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 367 views
  • 0 likes
  • 3 in conversation