Depending on the different formats and how long the list is you'll probably have to full around with this a little to get it right, but it's a good start and works with the current example:
data have; infile cards dsd dlm='***'; informat fullname $35.; format fullname $35.; input Fullname; cards; H FULLER WILLIAM D SMITHBURG BOONE POWELL JR. W. JAMES FARRELL SAMUEL C. SCOTT III DAVID A. L. OWEN, C.H., F.R.C.P. R. S. AUSTIN JAMES PACE Ann McLaughlin Korologos SUSAN CLARK-JOHNSON ;run; data want(keep=fullname first_name last_name); set have; First_Name=scan(fullname,1,' '); Last_Name=scan(fullname,2,' '); if length(last_name) < 3 then Last_Name = scan(fullname,3,' '); if length(last_name) < 3 then Last_Name = scan(fullname,4,' '); if length(scan(fullname,3,' ')) > 3 then last_name = scan(fullname,3,' '); run;
... View more