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