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
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;
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;
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;
Thanks, you are right
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.