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"'

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 1 reply
  • 650 views
  • 2 likes
  • 2 in conversation