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.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: