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

Hello,

 

How to put both single quotes (') and double quote (") into the same PRXCHANGE function?

I would like to change the company suffix 'LTD LIABILITY CO' to 'LLC' if it is not partioned by the following puncations which are () [] {} ' "  However, it seems that I cannot put the single and double quotes in the same PRXCHANGE function. Could you please give me some suggestion about this?

 

data have;
input string :$200.;
infile datalines ;
name_S25=prxchange('s/([^\w^\d])LTD[^\w^\d^\{^\}^\[^\]^\(^\)^\'^\"]+LIABILITY[^\w^\d^\{^\}^\[^\]^\(^\)^\'^\"]+CO([^\w^\d])/$1 LLC $2/',-1,cat(strip(compbl(name)),' '));
datalines;
APPLE LTD., LIABILITY CO
'APPLE LTD' LIABILITY CO
"APPLE LTD" LIABILITY CO
APPLE LTD (LIABILITY CO)
APPLE LTD [LIABILITY CO]
{APPLE LTD} LIABILITY CO ; run;

I expect to get 

name new_name 
APPLE LTD., LIABILITY CO APPLE LLC changed
'APPLE LTD' LIABILITY CO 'APPLE LTD' LIABILITY CO no change
APPLE LTD LIABILITY CO APPLE LTD LIABILITY CO no change
APPLE LTD (LIABILITY CO) APPLE LTD (LIABILITY CO) no change
APPLE LTD [LIABILITY CO] APPLE LTD [LIABILITY CO] no change
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

You don't need to do anything special to include a character that is different those used to enclose the string. So to express DON'T enclosed in double quotes you just need to type:

"DON'T"

If you want to include the character used to enclose the string then just double it.  So to express DON'T enclosed in single quotes you need to type:

'DON''T'

So to make a string that has both types of quotes one will be doubled and the other not, depending on what the outer characters are.

'"DON''T"'

 

View solution in original post

1 REPLY 1
Tom
Super User Tom
Super User

You don't need to do anything special to include a character that is different those used to enclose the string. So to express DON'T enclosed in double quotes you just need to type:

"DON'T"

If you want to include the character used to enclose the string then just double it.  So to express DON'T enclosed in single quotes you need to type:

'DON''T'

So to make a string that has both types of quotes one will be doubled and the other not, depending on what the outer characters are.

'"DON''T"'

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1035 views
  • 2 likes
  • 2 in conversation