Help using Base SAS procedures

Proper Name Case

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 8
Accepted Solution

Proper Name Case

Hi All,

I have a question about name casing. I've done a quick search on the forums but couldn't find anything initially, so I apologise if this question has been asked before, but I was wondering if anyone had any particular method for proper name casing?

By this I mean, you have all names in say lower case in a dataset containing customer names for example. You need to put together an email or mailing campaign to these customers, however you do not want to offend any of your customers by trying to proper case their surnames, which usually disregards second capitalisation (with surnames like O'Toole or McFarlane)

With my current knowledge I could easily format names so they look like;

Peter Mcfarlane

Robert O'toole

Or;

PETER MCFARLANE

ROBERT O'TOOLE

but I was wondering if anyone had an ingenious way of producing the proper case like;

Peter McFarlane

Robert O'Toole

I mean, is it a case that I'm going to need to set up a custom string of IF statements to check the string for certain characters? (this is what I would do I guess) Or, is there another ingenious and simple way to nail this type of issue?

~ Tom


Accepted Solutions
Solution
‎10-17-2014 08:40 AM
Respected Advisor
Posts: 4,173

Re: Proper Name Case

You don't get that "out-of-the-box" with Base SAS. If you have the Data Quality Server licensed then you could easily get it by using DQ functions for casing SAS(R) 9.3 Data Quality Server Reference

A compromise could be to use Propcase() and then some additional logic for defined cases as done in below sample code.

data sample;

  input name_string $40.;

  Name_Prop=propcase(name_string);

  Name_RegEx=prxchange("s/\bmc([[:alpha:]])/Mc\U\1/oi",-1,Name_Prop);

  Name_RegEx=prxchange("s/(?<=\b[[:alpha:]]')([[:alpha:]])/\U\1/oi",-1,Name_RegEx);

  datalines;

peter mcfarlane

claudia schiffer

robert o'toole

;

run;

View solution in original post


All Replies
Trusted Advisor
Posts: 1,913

Re: Proper Name Case

The PROPCASE command works on most words, but McFarlane, which has multiple capital letters, will fail.

Solution
‎10-17-2014 08:40 AM
Respected Advisor
Posts: 4,173

Re: Proper Name Case

You don't get that "out-of-the-box" with Base SAS. If you have the Data Quality Server licensed then you could easily get it by using DQ functions for casing SAS(R) 9.3 Data Quality Server Reference

A compromise could be to use Propcase() and then some additional logic for defined cases as done in below sample code.

data sample;

  input name_string $40.;

  Name_Prop=propcase(name_string);

  Name_RegEx=prxchange("s/\bmc([[:alpha:]])/Mc\U\1/oi",-1,Name_Prop);

  Name_RegEx=prxchange("s/(?<=\b[[:alpha:]]')([[:alpha:]])/\U\1/oi",-1,Name_RegEx);

  datalines;

peter mcfarlane

claudia schiffer

robert o'toole

;

run;

Super User
Super User
Posts: 7,942

Re: Proper Name Case

Its not even that consistent unfortunately.  If you have names from further afield there is different regional variations etc: http://en.wikipedia.org/wiki/Capitalization#Sentence_case_versus_title_case

My suggestion, find out what is "required" at output and what is actually stored currently and see if there is a compromise to be had, e.g. all upcase or something.  You might also want to remove identifiers completely e.g de-identification.

🔒 This topic is solved and locked.

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

Discussion stats
  • 3 replies
  • 424 views
  • 6 likes
  • 4 in conversation