Here is an example that adds another case with a middle name.
data split_names;
input name $25.;
datalines;
JohnDoe
SrinivasPavan
KishoreKumar
ChandrasekaRao
Ghandi
MaryJoeSmith
;
run;
data new;
set split_names;
len=length(name);
ucount = countc(name, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'U'); /* count the number of uppercase letters */
next=anyupper(substr(name,2));
upper=anyupper(name,-len); /* position of last uppercase letter */
if next=0 then first=name;
else first=substr(name,1,next);
if ucount=2 then last=substr(name,next+1);
else if ucount=3 then do;
middle=substr(name,next+1,len-upper-1);
last=substr(name,upper);
end;
run;
proc print data=new;
run;
... View more