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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 3 replies
  • 729 views
  • 0 likes
  • 3 in conversation