BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Feyng819
Obsidian | Level 7
Let’s say I wanna use prxchange to replace the string that starts with “The” or contain the word “world”. How can I use prxchange to achieve the multiple condition?

I only know that to replace the string starts with “the” would be prxchange(“s/\b^(The)\b/ /,-1,variable)
And to replace the string contains “world” would be prxchange(“s/\b(world)\b/ /,-1,variable)
Is there a way to combine the 2? Thanks!
1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hello @Feyng819,

 

The simplest way to combine the two replacements would be to apply the second PRXCHANGE function call to the result of the first, i.e., replace "variable" in the second call with the entire prxchange(...) expression of the first. In this particular case, however, it is also possible to use the OR operator (|) like this:

prxchange('s/^The\b|\bworld\b//',-1,variable);

This would remove the word "The" from the beginning of the string in variable as well as all occurrences of the word "world". (Note the case-sensitivity without the "i" modifier at the end of the regular expression.)

View solution in original post

2 REPLIES 2
FreelanceReinh
Jade | Level 19

Hello @Feyng819,

 

The simplest way to combine the two replacements would be to apply the second PRXCHANGE function call to the result of the first, i.e., replace "variable" in the second call with the entire prxchange(...) expression of the first. In this particular case, however, it is also possible to use the OR operator (|) like this:

prxchange('s/^The\b|\bworld\b//',-1,variable);

This would remove the word "The" from the beginning of the string in variable as well as all occurrences of the word "world". (Note the case-sensitivity without the "i" modifier at the end of the regular expression.)

Feyng819
Obsidian | Level 7
Thanks for your help it works perfectly!

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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