extracting first and last name

Reply
Occasional Contributor
Posts: 19

extracting first and last name

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.

Super User
Posts: 20,236

Re: extracting first and last name

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.

SAS Super FREQ
Posts: 379

Re: extracting first and last name

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 
Occasional Contributor
Posts: 19

Re: extracting first and last name

Posted in reply to WarrenKuhfeld

will give this a try.  Thanks very much.

Ask a Question
Discussion stats
  • 3 replies
  • 147 views
  • 2 likes
  • 3 in conversation