STEVENS MD,STEVE ROBERT |
WAINWRIGHT MD,LISA S N |
DUDLEY DDS,WARREN |
KARZ MD REX H |
BROWN,RED |
DE LA HOYA OD,RACSO B |
Need to extract first and last name from a provider list. Most records contain a title (MD, OD, PT, CRNP, etc) but not all.
The first name on the above list is the most frequent format on the list but there are many other formats - as shown by
records 2-6 above. Using 9.4
Thanks.
So what's the rules you've developed so far?
Can you show what you'd expect as output?
I think SCAN will get you most of the way there, but there are some formats that will be problematic for sure.
Something along these lines might be enough to get you started. This code could fail if a name begins with "OD" and for other reasons. You might want to deal with the degrees a bit differently.
data x(drop=n);
input n $ 1-40;
name = n;
n = tranwrd(n, ' MD', ' ');
n = tranwrd(n, ' DDS', ' ');
n = tranwrd(n, ' OD', ' ');
if find(n, ',') then last = scan(n, 1, ',');
else last = scan(n, 1, ' ');
if find(n, ',') then first = scan(n, 2, ',');
else first = scan(n, 2, ' ');
first = scan(first, 1);
datalines;
STEVENS MD,STEVE ROBERT
WAINWRIGHT MD,LISA S N
DUDLEY DDS,WARREN
KARZ MD REX H
BROWN,RED
DE LA HOYA OD,RACSO B
;
proc print; run;
Obs name last first
1 STEVENS MD,STEVE ROBERT STEVENS STEVE
2 WAINWRIGHT MD,LISA S N WAINWRIGHT LISA
3 DUDLEY DDS,WARREN DUDLEY WARREN
4 KARZ MD REX H KARZ REX
5 BROWN,RED BROWN RED
6 DE LA HOYA OD,RACSO B DE LA HOYA RACSO
will give this a try. Thanks very much.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.