DATA Step, Macro, Functions and more

Replace strings at end using prxchange

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

Replace strings at end using prxchange

Hi,

 

I am trying to search and replace a string of numbers at the end of a variable. If the string of numbers occur in the middle or begining I want to keep them. Below is my example.

 

data test;
input test $32.;
retain pattern_num;
if _n_=1 then pattern_num=prxparse("s/#\d+$/ /");
test2=prxchange(pattern_num,-1,COMPBL(test));
datalines;
MARKET #1234
#1 MARKET
MARKET STORE #12
 ;
run;

 

 

I would like test2 to look like

 

MARKET

#1 MARKET
MARKET STORE

Thanks!


Accepted Solutions
Solution
‎11-03-2015 06:24 PM
Respected Advisor
Posts: 3,124

Re: Replace strings at end using prxchange

You are almost there. 

 

test2=prxchange(pattern_num,-1,COMPBL(trim(test)));

View solution in original post


All Replies
Solution
‎11-03-2015 06:24 PM
Respected Advisor
Posts: 3,124

Re: Replace strings at end using prxchange

You are almost there. 

 

test2=prxchange(pattern_num,-1,COMPBL(trim(test)));
New Contributor
Posts: 3

Re: Replace strings at end using prxchange

Thank You!!!!

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 198 views
  • 1 like
  • 2 in conversation