1) I ran next code. check the lo - there is no word='III' - only 'II'.
data K5;
set K4;
new_FirstName = FirstName;
*length suffix $ 7;
do word= 'JR', 'SR', 'II', 'III', 'IV' ;
new_FirstName = tranwrd(' '||strip(new_FirstName), ' '||strip(word)||' ', ' ');
put word= new_FirstName=;
new_FirstName = compbl(new_FirstName);
end;
run;
The reason - first word='JR' - only 2 characters, therefore length of word is 2.
Add the statement: length word $3; or the max length of all words.
2) The syntax of tranwrd() function is:
TRANWRD(source,target,replacement)
I ran next code:
data _NULL_;
length FirstName new_FirstName $13 word $3;
FirstName = 'III';
word = 'III';
new_FirstName = tranwrd(' '||strip(new_FirstName), ' '||strip(word)||' ', ' ');
put FirstName= new_FirstName=;
run;
the result in log is: FirstName=III new_FirstName=
Is that what you want ? Pay attention to strip() added for New_FirstName,
and to LENGTH applying to WORD and to New_FirstName.
3) In all your DO;...END; parts there is only one statement to do;
Why not just: if findw(FirstName, 'JR')>0 then suffix='JR';
the same for all other suffixes.
4) I don't understand why you call it "suffix" if you relate to the whole string of
FirstName ?
... View more