DATA Step, Macro, Functions and more

PROPCASE not Acronym

Accepted Solution Solved
Reply
Contributor
Posts: 58
Accepted Solution

PROPCASE not Acronym

Hello,

 

I need how converting the first letter of each word on a title excluding the acronym. Please see below:

 

data HAVE;

input title $40.;

cards;

 

PRINCIPAL ABC SCHOOL

ACCT TEACHER CBS SCHOOL

MATH TEACHER NY SCHOOL

run;

DATA title;

SET HAVE;

title2 = PROPCASE(TITLE);

RUN;

 

The result should be:

Principal ABC School

ACCT Teacher CBS School

Math Teacher NY School

 

Thank you.


Accepted Solutions
Solution
a week ago
Super User
Posts: 13,924

Re: PROPCASE not Acronym

[ Edited ]

@BonnaryW wrote:
Thank you for responding to my post. It work. Now, I am having problem with title have special characters (',' , '&', '/') , it get drop off from the title.

Your example data should provide examples of all of the types of values you need to address.

Since you do not show an example yet with special characters we can't tell what you may want to do with them.

blank ! $ % & ( ) * + , - . / ; < ^ |  are standard delimiters for the SCAN function and would break words bits by those characters and NOT include them in the output.. If the only character you want as a delimiter is the space character then modify the scan function call as:

 

word =scan(title,i,' ');

 

 But if any of your bits with the special characters include a mix of acronym and non-acronym the coding is going to get more complex.

 

View solution in original post


All Replies
Super User
Posts: 13,924

Re: PROPCASE not Acronym

Do have a list of all of the acronyms to avoid?

If not you will have to be able to provide some rule(s) for which strings are acromyns and which aren't. And with all of the organizations out there the work to create acronyms that spell a related word lots of luck finding a rule that will work.

 

You may be able to extract each "word" using scan and testing the value against a list using IN something like:

data HAVE;
input title $40.;
length newtitle word $ 40. ;
do i= 1 to countw(title);
   word =scan(title,i); 
   if word  not in ('ABC','ACCT','CBS' 'NY') then newtitle=catx(' ',newtitle,propcase(word));
   else newtitle = catx(' ',newtitle,word);
end;
drop i word;
cards;
PRINCIPAL ABC SCHOOL
ACCT TEACHER CBS SCHOOL
MATH TEACHER NY SCHOOL
run;
Contributor
Posts: 58

Re: PROPCASE not Acronym

Thank you for responding to my post. It work. Now, I am having problem with title have special characters (',' , '&', '/') , it get drop off from the title.
Super User
Posts: 2,505

Re: PROPCASE not Acronym

propcase() does not remove these. 

Do you want to remove them? If so, use the compress function.

Solution
a week ago
Super User
Posts: 13,924

Re: PROPCASE not Acronym

[ Edited ]

@BonnaryW wrote:
Thank you for responding to my post. It work. Now, I am having problem with title have special characters (',' , '&', '/') , it get drop off from the title.

Your example data should provide examples of all of the types of values you need to address.

Since you do not show an example yet with special characters we can't tell what you may want to do with them.

blank ! $ % & ( ) * + , - . / ; < ^ |  are standard delimiters for the SCAN function and would break words bits by those characters and NOT include them in the output.. If the only character you want as a delimiter is the space character then modify the scan function call as:

 

word =scan(title,i,' ');

 

 But if any of your bits with the special characters include a mix of acronym and non-acronym the coding is going to get more complex.

 

Contributor
Posts: 58

Re: PROPCASE not Acronym

Thank you everyone for your response.
☑ This topic is solved.

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

Discussion stats
  • 5 replies
  • 90 views
  • 1 like
  • 3 in conversation