Sample 25252: Searching for a pattern in a character string using PRXPARSE and PRXMATCH
PRXPARSE compiles a Perl regular expression (PRX) that can be used for pattern matching of a character value. PRXMATCH searches the specified string for the parsed pattern and returns the position of the matched pattern, if one is found.
Note: Perl Regular Expresssions are new in SAS 9.0.
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
/* For efficiency, compile the pattern to be located only once on the first */
/* iteration of the DATA step. This sample is looking for the pattern */
/* capital E, capital R, capital R, capital O, capital R, zero or one space, */
/* zero or more digits, an optional hyphen, zero or more digits, and a colon. */
data _null_;
infile datalines truncover;
if _N_=1 then pattern=prxparse("/ERROR ?(\d*)-?(\d*):/");
retain pattern;
input test $80.;
position=PRXMATCH(pattern,test);
put test= position=;
datalines;
NOTE: One or more lines were truncated.
Error: This is a home-made error message using lowercase.
ERROR: SAS stopped processing due to errors.
ERROR 180-322: Statement used out of order.
ERROR 22-7: Invalid option name S.
ERROR: Libname _IMEX_ is not assigned.
;
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
OUTPUT to SAS log
test=NOTE: One or more lines were truncated. position=0
test=Error: This is a home-made error message using lowercase. position=0
test=ERROR: SAS stopped processing due to errors. position=1
test=ERROR 180-322: Statement used out of order. position=1
test=ERROR 22-7: Invalid option name S. position=1
test=ERROR: Libname _IMEX_ is not assigned. position=1
PRXPARSE compiles a Perl regular expression (PRX) that can be used for pattern matching of a character value. PRXMATCH searches the specified string for the parsed pattern and returns the position of the matched pattern, if one is found.
Type: | Sample |
Topic: | SAS Reference ==> DATA Step SAS Reference ==> Functions
|
Date Modified: | 2005-12-17 03:02:48 |
Date Created: | 2005-03-06 10:13:51 |
Operating System and Release Information
SAS System | Base SAS | All | 9 TS M0 | n/a |