DATA Step, Macro, Functions and more

remove salutations in name

Accepted Solution Solved
Reply
Regular Contributor
Posts: 228
Accepted Solution

remove salutations in name

Hi everyone.

 

Can I please ask how can I remove the salutations ie Mr, Ms, Mrs, Miss, Dr. from the variable 'name' in my data?

 

Thank you.


Accepted Solutions
Solution
‎09-18-2016 12:41 AM
Trusted Advisor
Posts: 1,555

Re: remove salutations in name

Usually salutations are the first/prefix of a name followd by a space.

In such case :

 

%let salut_list = Mr Ms Mrs Miss Dr. ;

data want;

  set have;

        test = scan(name,1) ;

        if test in (&salut_list) 

        then name = left(substr(name, length(test)+1));

       /* drop or rename test to salut */

run;

View solution in original post


All Replies
Super User
Posts: 19,772

Re: remove salutations in name

Use TRANWRD but you need to be careful and test it. 

 

For example, if you try and replace Miss, what about a first name as Missy? 

Solution
‎09-18-2016 12:41 AM
Trusted Advisor
Posts: 1,555

Re: remove salutations in name

Usually salutations are the first/prefix of a name followd by a space.

In such case :

 

%let salut_list = Mr Ms Mrs Miss Dr. ;

data want;

  set have;

        test = scan(name,1) ;

        if test in (&salut_list) 

        then name = left(substr(name, length(test)+1));

       /* drop or rename test to salut */

run;

Trusted Advisor
Posts: 1,555

Re: remove salutations in name

change to:
%let salut_list = "Mr" "Ms" "Mrs" "Miss" "Dr." ;
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 457 views
  • 1 like
  • 3 in conversation