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
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;
Try PROC TRANSPOSE:
proc transpose
data=have
out=want (
drop=_name_
rename=(col1=icd_code)
where=(icd_code ne "")
)
;
by studynum;
var icd:;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.