I have a data set with a bunch of code as example below. I want to delete the code BH1003 for all LOB’s except HAR.
Any help with SAS code is much appreciated.
Code LOB
BH1003 HAR
BH1003 LIP
BH1003,BH1005,BH1007 LIP
BH1005 MA
AEHJ IP
BH1003,BH1006,BH1008 HAR
BH1006,BH1003,BH1004 CCC
Want
Code LOB
BH1003 HAR
BH1005,BH1007 LIP
BH1005 MA
AEHJ IP
BH1003,BH1006,BH1008 HAR
BH1006, BH1004 CCC
Hi @cho16 See if this helps
data have;
input Code :$30. LOB $;
cards;
BH1003 HAR
BH1003 LIP
BH1003,BH1005,BH1007 LIP
BH1005 MA
AEHJ IP
BH1003,BH1006,BH1008 HAR
BH1006,BH1003,BH1004 CCC
;
data want;
set have;
length want $100;
if lob ne 'HAR' then
do _n_=1 to countw(code,',');
if scan(code,_n_,',')='BH1003' then continue;
want=catx(',',want,scan(code,_n_,','));
end;
else want=code;
if want>' ';
run;
data want;
set have;
if LOB ne 'HAR' then do;
code= tranwrd(code,'BH1003,','' );
code= tranwrd(code,'BH1003','' );
end;
if code = '' then delete;
run;
or this way.
data have;
input Codes :$40. LOB $;
datalines;
BH1003 HAR
BH1003 LIP
BH1003,BH1005,BH1007 LIP
BH1005 MA
AEHJ IP
BH1003,BH1006,BH1008 HAR
BH1006,BH1003,BH1004 CCC
;
data want;
set have;
if lob ne 'HAR' then
do;
codes=prxchange('s/\bBH1003\b,?//oi',-1,strip(codes));
if missing(codes) then delete;
end;
run;
proc print;
run;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: