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

Hi all - I would like to use a single quote in the PRXCHANGE function as follows:

 

new_text_field = PRXCHANGE('s/([A-Z]\w+)(?=s)/$1\'/',-1,text_field);

 

But the above returns an error. It doesn't like that single quote in the pink section. I know these are a pain to read but this would ideally scan text for words that end in 's' and replace them so that they end in 's basically making them possessive. This works if I use a dash instead of a single quote.

 

Any idea how to make it accept the single quote?

1 ACCEPTED SOLUTION

Accepted Solutions
FriedEgg
SAS Employee

You are going to get unwanted results unless you modify the regular expression to look for a word boundary too

 

data have;
input text_field $10.;
cards;
Expression
Tools
;
run;

data want;
set have;
new_text_field=prxchange('s/([A-Z]\w+)(?=s)/$1''/',-1,text_field);
foo_text_field=prxchange('s/([A-Z]\w+)(?=s\b)/$1''/',-1,text_field);
put (text_field new_text_field foo_text_field) (/=);
run;

 

text_field=Expression
new_text_field=Expres'sion
foo_text_field=Expression

text_field=Tools
new_text_field=Tool's
foo_text_field=Tool's

View solution in original post

4 REPLIES 4
PGStats
Opal | Level 21

Use double quotes to surround a string with a single quote inside

 

new_text_field = PRXCHANGE("s/([A-Z]\w+)(?=s)/$1'/", -1, text_field);

PG
FriedEgg
SAS Employee

You are going to get unwanted results unless you modify the regular expression to look for a word boundary too

 

data have;
input text_field $10.;
cards;
Expression
Tools
;
run;

data want;
set have;
new_text_field=prxchange('s/([A-Z]\w+)(?=s)/$1''/',-1,text_field);
foo_text_field=prxchange('s/([A-Z]\w+)(?=s\b)/$1''/',-1,text_field);
put (text_field new_text_field foo_text_field) (/=);
run;

 

text_field=Expression
new_text_field=Expres'sion
foo_text_field=Expression

text_field=Tools
new_text_field=Tool's
foo_text_field=Tool's
bluth_family
Fluorite | Level 6

Thank you to both!

 

And yes I have not yet tackled the word boundary issue but I am aware of it. Good advice.

 

Thank you!

bluth_family
Fluorite | Level 6
Well I meant to mark this as the solution. Now I can't undo it. I am a dork.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 4 replies
  • 2425 views
  • 2 likes
  • 3 in conversation