CALL PRXNEXT Routine


CALL PRXNEXT Routine

Returns the position and length of a substring that matches a pattern and iterates over multiple matches within one string

Category: Character String Matching

Restriction: Use with the PRXPARSE function

Syntax

CALL PRXNEXT ( regular-expression -id , start , stop , source , position , length );

Arguments

regular-expression-id

  • specifies a numeric identification number that is returned by the PRXPARSE function.

start

  • is a numeric value that specifies the position at which to start the pattern matching in source . If the match is successful, CALL PRXNEXT returns a value of position + MAX(1, length ). If the match is not successful, the value of start is not changed.

stop

  • is a numeric value that specifies the last character to use in source . If stop is -1, then the last character is the last non-blank character in source .

source

  • specifies the character expression that you want to search.

position

  • specifies the numeric position in source at which the pattern begins. If no match is found, CALL PRXNEXT returns zero.

length

  • specifies a numeric value that is the length of the string that is matched by the pattern. If no match is found, CALL PRXNEXT returns zero.

Details

The CALL PRXNEXT routine searches the variable source with a pattern. It returns the position and length of a pattern match that is located between the start and the stop positions in source . Because the value of the start parameter is updated to be the position of the next character that follows a match, CALL PRXNEXT enables you to search a string for a pattern multiple times in succession.

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

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 finds all instances of cat, rat, or bat in a text string.

 data _null_;     ExpressionID = prxparse('/[crb]at/');     text = 'The woods have a bat, cat, and a rat!';     start = 1;     stop = length(text);        /* Use PRXNEXT to find the first instance of the pattern, */        /* then use DO WHILE to find all further instances.       */        /* PRXNEXT changes the start parameter so that searching  */        /* begins again after the last match.                     */     call prxnext(ExpressionID, start, stop, text, position, length);        do while (position > 0);           found = substr(text, position, length);           put found= position= length=;           call prxnext(ExpressionID, start, stop, text, position, length);        end;  run; 

The following lines are written to the SAS log:

 found=bat position=18 length=3  found=cat position=23 length=3  found=rat position=34 length=3 

See Also

Functions and CALL routines:

  • 'CALL PRXCHANGE Routine' on page 354

  • 'CALL PRXDEBUG Routine' on page 356

  • 'CALL PRXFREE Routine' on page 358

  • 'CALL PRXPOSN Routine' on page 361

  • 'CALL PRXSUBSTR Routine' on page 364

  • 'CALL PRXCHANGE Routine' on page 354

  • 'PRXCHANGE Function' on page 739

  • 'PRXPAREN Function' on page 747

  • 'PRXMATCH Function' on page 743

  • 'PRXPARSE Function' on page 748

  • 'PRXPOSN Function' on page 750




SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3
SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 704

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net