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 |
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"'
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"'
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.