Hi,
you need to stop the loop after a replacement is made and stop overwriting new_policy_number over and over again until you try to replace with 'MANUALCEDED' which always fails.
data test_set ;
infile datalines truncover;
input policy_number $100. ;
datalines;
Q2 2017 Manual Entry
000123400
Manual
Manual_fix15
Manual_fix22Q1
Manual All Data
0098765401CededManual
0098765401Manual
0011223301 CededManual
;
run;
data chk;
set test_set;
length new_policy_number $100;
retain new_policy_number ;
array nn[4] $50 _temporary_ ('MANUALENTRY' 'MANUAL' 'CEDEDMANUAL' 'MANUALCEDED');
do i=1 to dim(nn);
new_policy_number = upcase(compress(tranwrd(policy_number,'_','')));
if index(new_policy_number,nn[i]) then do;
new_policy_number = tranwrd(new_policy_number,nn[i], '') ;
leave;
end;
end;
drop i;
run;
Please also note that in obs #7 you're first replacing with manual since it comes first in your array and not 'cededmanual'
... View more