Hello,
In my dataset each row cointains information about one individual and their diagnosis code. The information on each individual's different diagnos is stored in one variable that can contain multiple diagnosis ( see 'data have'). I would like to split each diagnos code in to separate variables. ('data want').
data have;
input id $ ICD $;
cards;
1 I63 H45 T11
2 C03 D25
3 J11 S54 A10 R45
;
run;
Data want;
id $ ICD1 $ ICD2 $ ICD3 $ ICD4 $;
1 I63 H45 T11 .
2 C03 D25 . .
3 J11 S54 A10 R45
;
run;
Thanks in advance!
Much better: split it into observations:
data want;
set have (rename=(icd=_icd));
length icd $3;
do i = 1 to countw(_icd);
icd = scan(_icd,i);
output;
end;
keep id icd;
run;
Much better: split it into observations:
data want;
set have (rename=(icd=_icd));
length icd $3;
do i = 1 to countw(_icd);
icd = scan(_icd,i);
output;
end;
keep id icd;
run;
Hi @Chris_LK_87 Do all those ICD's consistently have a length of 3 bytes?
1. Format your SAS code using the "SAS Code" icon.
2. When I paste your code into SAS, the first data step doesn't give the correct results. The second data step fails.
BZZZZZZZZZZZZZZZZZZZZZZZ! Try again.
P.S.: Use the SCAN function and PROC TRANSPOSE (or an array - TRANSPOSE would be more flexible). Read the doc for more details.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.