Performs a pattern-matching replacement.
Category: | Character String Matching |
specifies a character constant, variable, or expression with a value that is a Perl regular expression.
specifies a numeric variable with a value that is a pattern identifier that is returned from the PRXPARSE function.
Restriction | If you use this argument, you must also use the PRXPARSE function. |
is a numeric constant, variable, or expression that specifies the number of times to search for a match and replace a matching pattern.
Tip | If the value of times is –1, then matching patterns continue to be replaced until the end of source is reached. |
specifies a character constant, variable, or expression that you want to search.
/* Create a data set that contains a list of names. */ data ReversedNames; input name & $32.; datalines; Jones, Fred Kavich, Kate Turley, Ron Dulix, Yolanda ; /* Reverse last and first names with a DATA step. */ data names; set ReversedNames; name = prxchange('s/(\w+), (\w+)/$2 $1/', -1, name); run; proc print data=names; run;
data names; input name & $32.; datalines; Ron Turley Judy Donnelly Kate Kavich Tully Sanchez ; data ReversedNames; input name & $32.; datalines; Jones, Fred Kavich, Kate Turley, Ron Dulix, Yolanda ; proc sql; create table NewNames as select a.name from names as a, ReversedNames as b where a.name = prxchange('s/(\w+), (\w+)/$2 $1/', -1, b.name); quit; proc print data=NewNames; run;
data _null_; length txt $32; txt = prxchange ('s/(big)(black)(bear)/\U$1\L$2\E$3/', 1, 'bigblackbear'); put txt=; run;
/* Create data set that contains confidential information. */ data a; input text $80.; datalines; The phone number for Ed is (801)443-9876 but not until tonight. He can be reached at (910)998-8762 tomorrow for testing purposes. ; run; /* Locate confidential phone numbers and replace them with message */ /* indicating that they have been removed. */ data b; set a; text = prxchange('s/\([2-9]\d\d\) ?[2-9]\d\d-\d\d\d\d/*PHONE NUMBER REMOVED*/', -1, text); put text=; run; proc print data = b; run;