CALL PRXSUBSTR Routine
Returns the position and length of a substring that matches a pattern.
| Category: | Character String Matching |
| Restrictions: | Use with the PRXPARSE function. |
| This function is not valid on the CAS server. | |
| Do not use this function to process DBCS and MBCS data, because this CALL routine requires the PRXPARSE function, which is not DBCS compatible. | |
| Interaction: | When invoked by the %SYSCALL macro statement, CALL PRXSUBSTR removes the quotation marks from its arguments. For more information, see Using CALL Routines and the %SYSCALL Macro Statement. |
| Notes: | Argument types for arguments that are updated must match in CALL routines. All argument types must be CHAR, VARCHAR, or NUMERIC. If the argument types do not match, a warning is issued to the log. |
| SAS has adopted the International Components for Unicode (ICU). ICU enables SAS to apply regular expression matching to Unicode string data. For more information, see Regular Expressions. |
Syntax
Required Arguments
regular-expression-id
specifies a numeric variable with a value that is an identification number that is returned by the PRXPARSE function.
source
specifies a character constant, variable, or expression that you want to search.
position
is a numeric variable with a returned value that is the position in source where the pattern begins. If no match is found, CALL PRXSUBSTR returns zero.
Optional Argument
length
is a numeric variable with a returned value that is the length of the substring that is matched by the pattern. If no match is found, CALL PRXSUBSTR returns zero.
Details
Comparisons
Examples
Example 1: Finding the Position and Length of a Substring
data _null_;
/* Use PRXPARSE to compile the Perl regular expression. */
patternID = prxparse('/world/');
/* Use PRXSUBSTR to find the position and length of the string. */
call prxsubstr(patternID, 'Hello world!', position, length);
put position= length=;
run;position=7 length=5
Example 2: Finding a Match in a Substring
data _null_;
if _N_ = 1 then
do;
retain ExpressionID;
/* The i option specifies a case insensitive search. */
pattern = "/ave|avenue|dr|drive|rd|road/i";
ExpressionID = prxparse(pattern);
end;
input street $80.;
call prxsubstr(ExpressionID, 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
;
run;"Ave" found in "6789 64th Ave" "Road" found in "4 Moritz Road"