SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3

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

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

Arguments

regular-expression-id

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 'Syntax of Perl Regular Expressions' on page 262.

For more information about pattern matching, see 'Pattern Matching Using SAS Regular Expressions (RX) and Perl Regular Expressions (PRX)' on page 260.

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.

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' on page 270.

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 = "/aveavenuedrdriverdroad/i"; patternID = prxparse(pattern); end; input street .; 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:

Категории