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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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