パターンマッチングの置換を実行します。
| カテゴリ: | 文字列マッチング |
| 制限事項: | regular-expression-id引数を使用する場合、この引数にはDBCS互換性がないPRXPARSE関数が必要なため、DBCSおよびMBCSデータは処理できません。 |
/* 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 ReversedNames;
input name & $32.;
datalines;
Jones, Fred
Kavich, Kate
Turley, Ron
Dulix, Yolanda
;
proc sql;
create table names as
select prxchange('s/(\w+), (\w+)/$2 $1/', -1, name) as name
from ReversedNames;
quit;
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;txt=BIGblackbear
/* 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;