パターンの一致を検索し、見つかったパターンの位置を返します。
| カテゴリ: | 文字列マッチング |
| 制限事項: | regular-expression-id引数を使用する場合、この引数にはDBCS互換性がないPRXPARSE関数が必要なため、DBCSおよびMBCSデータは処理できません。 |
/* For release 9.0: the following example makes a call to PRXPARSE. */ /* For release 9.1, no call is required. */
data _null_;
/* Use PRXPARSE to compile the Perl regular expression. */
patternID=prxparse('/world/');
/* Use PRXMATCH to find the position of the pattern match. */
position=prxmatch(patternID, 'Hello world!');
put position=;
run;position=7
data _null_;
/* Use PRXMATCH to find the position of the pattern match. */
position=prxmatch('/world/', 'Hello world!');
put position=;
run;position=7
data _null_;
if _N_=1 then
do;
retain PerlExpression;
pattern="/(\d+):(\d\d)(?:\.(\d+))?/";
PerlExpression=prxparse(pattern);
end;
array match[3] $ 8;
input minsec $80.;
position=prxmatch(PerlExpression, minsec);
if position ^= 0 then
do;
do i=1 to prxparen(PerlExpression);
call prxposn(PerlExpression, i, start, length);
if start ^= 0 then
match[i]=substr(minsec, start, length);
end;
put match[1] "minutes, " match[2] "seconds" @;
if ^missing(match[3]) then
put ", " match[3] "milliseconds";
end;
datalines;
14:56.456
45:32
;
run;14 minutes, 56 seconds, 456 milliseconds 45 minutes, 32 seconds
data ZipCodes;
input name: $16. zip:$10.;
datalines;
Johnathan 32523-2343
Seth 85030
Kim 39204
Samuel 93849-3843
;
/* Extract ZIP+4 ZIP codes with the DATA step. */
data ZipPlus4;
set ZipCodes;
where prxmatch('/\d{5}-\d{4}/', zip);
run;
proc print data=ZipPlus4;
run;data ZipCodes;
input name: $16. zip:$10.;
datalines;
Johnathan 32523-2343
Seth 85030
Kim 39204
Samuel 93849-3843
;
/* Extract ZIP+4 ZIP codes with PROC SQL. */
proc sql;
create table ZipPlus4 as
select * from ZipCodes
where prxmatch('/\d{5}-\d{4}/', zip);
run;
proc print data=ZipPlus4;
run;