Previous Page | Next Page

Functions and CALL Routines

PRXPARSE Function



Compiles a Perl regular expression (PRX) that can be used for pattern matching of a character value.
Category: Character String Matching
Restriction: Use with other Perl regular expressions.

Syntax
Arguments
Details
The Basics
Compiling a Perl Regular Expression
Comparisons
Examples
See Also

Syntax

regular-expression-id=PRXPARSE (perl-regular-expression)

Arguments

regular-expression-id

is a numeric pattern identifier that is returned by the PRXPARSE function.

perl-regular-expression

specifies a character value that is a Perl regular expression.


Details


The Basics

The PRXPARSE function returns a pattern identifier number that is used by other Perl functions and CALL routines to match patterns. If an error occurs in parsing the regular expression, SAS returns a missing value.

PRXPARSE uses metacharacters in constructing a Perl regular expression. To view a table of common metacharacters, see Tables of Perl Regular Expression (PRX) Metacharacters.

For more information about pattern matching, see Pattern Matching Using Perl Regular Expressions (PRX).


Compiling a Perl Regular Expression

If perl-regular-expression is a constant or if it uses the /o option, the Perl regular expression is compiled only once. Successive calls to PRXPARSE will not cause a recompile, but will return the regular-expression-id for the regular expression that was already compiled. This behavior simplifies the code because you do not need to use an initialization block (IF _N_ =1) to initialize Perl regular expressions.

Note:   If you have a Perl regular expression that is a constant, or if the regular expression uses the /o option, then calling PRXFREE to free the memory allocation results in the need to recompile the regular expression the next time that it is called by PRXPARSE.

The compile-once behavior occurs when you use PRXPARSE in a DATA step. For all other uses, the perl-regular-expression is recompiled for each call to PRXPARSE.   [cautionend]


Comparisons

The Perl regular expression (PRX) functions and CALL routines work together to manipulate strings that match patterns. To see a list and short description of these functions and CALL routines, see the Character String Matching category in Functions and CALL Routines by Category.


Examples

The following example uses metacharacters and regular characters to construct a Perl regular expression. The example parses addresses and writes formatted results to the SAS log.

data _null_;
   if _N_ = 1 then 
   do;
      retain patternID;

         /* The i option specifies a case insensitive search. */
      pattern = "/ave|avenue|dr|drive|rd|road/i";
      patternID = prxparse(pattern);
   end;

   input street $80.;
   call prxsubstr(patternID, street, position, length);
   if position ^= 0 then
   do;
      match = substr(street, position, length);
      put match:$QUOTE. "found in " street:$QUOTE.;
   end;
   datalines;
153 First Street
6789 64th Ave
4 Moritz Road
7493 Wilkes Place
;

The following lines are written to the SAS log:

   "Ave" found in "6789 64th Ave"
   "Road" found in "4 Moritz Road"


See Also

Functions and CALL routines:

CALL PRXCHANGE Routine

CALL PRXDEBUG Routine

CALL PRXFREE Routine

CALL PRXNEXT Routine

CALL PRXPOSN Routine

CALL PRXSUBSTR Routine

CALL PRXCHANGE Routine

PRXCHANGE Function

PRXPAREN Function

PRXMATCH Function

PRXPOSN Function

Previous Page | Next Page | Top of Page