BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
desireatem
Pyrite | Level 9

Dear Sir/Madam,

 

I have data set with variable CodedDCList as below. I want to separate it and create many different variables such that it should look like table 2 below. Please Help me with the code

 

 

 

SAS Output

Obs CodedDxList
1 E78.5 -- Other and unspecified hyperlipidemia; R06.09, R09.89 -- Other dyspnea and respiratory abnormality; I10 -- Unspecified essential hypertension; J44.9 -- Chronic airway obstruction, not elsewhere classified; K21.9 -- Esophageal reflux; M17.10 -- Osteoarthrosis, unspecified whether generalized or localized, lower leg; K44.9 -- Diaphragmatic hernia without mention of obstruction or gangrene
2 I10 -- Unspecified essential hypertension; E04.2 -- Nontoxic multinodular goiter; E78.5 -- Other and unspecified hyperlipidemia
   

 

Table 2
Code1             Code2              Code 3           Code4        Code5       Code6            Code
1)  E78.5          R06.09, R09.89         I10               J44.9        K21.9            M17.10               K44.

            

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

quick and lazy approach:

data have;
infile datalines truncover;
input Obs $ CodedDxList & $800.;
datalines4;
1	E78.5 -- Other and unspecified hyperlipidemia; R06.09, R09.89 -- Other dyspnea and respiratory abnormality; I10 -- Unspecified essential hypertension; J44.9 -- Chronic airway obstruction, not elsewhere classified; K21.9 -- Esophageal reflux; M17.10 -- Osteoarthrosis, unspecified whether generalized or localized, lower leg; K44.9 -- Diaphragmatic hernia without mention of obstruction or gangrene
2	I10 -- Unspecified essential hypertension; E04.2 -- Nontoxic multinodular goiter; E78.5 -- Other and unspecified hyperlipidemia
;;;;

data want;
set have;
array code(100) $20;
k=countw(CodedDxList,'--');
do _n_=1 to k-1;
code(_n_)=scan(scan(CodedDxList,_n_,'--'),-1,';');
end;
drop k;
run;

View solution in original post

3 REPLIES 3
novinosrin
Tourmaline | Level 20

quick and lazy approach:

data have;
infile datalines truncover;
input Obs $ CodedDxList & $800.;
datalines4;
1	E78.5 -- Other and unspecified hyperlipidemia; R06.09, R09.89 -- Other dyspnea and respiratory abnormality; I10 -- Unspecified essential hypertension; J44.9 -- Chronic airway obstruction, not elsewhere classified; K21.9 -- Esophageal reflux; M17.10 -- Osteoarthrosis, unspecified whether generalized or localized, lower leg; K44.9 -- Diaphragmatic hernia without mention of obstruction or gangrene
2	I10 -- Unspecified essential hypertension; E04.2 -- Nontoxic multinodular goiter; E78.5 -- Other and unspecified hyperlipidemia
;;;;

data want;
set have;
array code(100) $20;
k=countw(CodedDxList,'--');
do _n_=1 to k-1;
code(_n_)=scan(scan(CodedDxList,_n_,'--'),-1,';');
end;
drop k;
run;
ballardw
Super User

From what the OP shows I think this modification of @novinosrin's code gets a bit closer.

 

data want;
   set have;
   array code(100) $25;/* the length here needs to be large enough the hold the maximum number of codes *8 */
   k=countw(CodedDxList,';');
   do _n_=1 to k;
      code(_n_)=strip(scan(scan(CodedDxList,_n_,';'),1,'--'));
   end;
   drop k;
run;
desireatem
Pyrite | Level 9

Thanks, you are right

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 1204 views
  • 0 likes
  • 3 in conversation