BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
BonnaryW
Obsidian | Level 7

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.

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@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

5 REPLIES 5
ballardw
Super User

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;
BonnaryW
Obsidian | Level 7
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.
ChrisNZ
Tourmaline | Level 20

propcase() does not remove these. 

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

ballardw
Super User

@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.

 

BonnaryW
Obsidian | Level 7
Thank you everyone for your response.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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