CALL PRXCHANGE Routine


Performs a pattern-matching replacement

Category: Character String Matching

Restriction: Use with the PRXPARSE function.

Syntax

CALL PRXCHANGE ( regular-expression -id , times , old-string <, new-string <, result-length <, truncation -value <, number-of-changes >>>>);

Arguments

regular-expression-id

  • specifies a numeric pattern identifier that is returned from the PRXPARSE function.

times

  • is a numeric value that specifies the number of times to search for a match and replace a matching pattern.

  • Tip: If the value of times is -1, then all matching patterns are replaced .

old-string

  • specifies the character expression on which to perform a search and replace.

  • Tip: All changes are made to old-string if you do not use the new-string argument.

new-string

  • specifies a character variable in which to place the results of the change to old-string .

  • Tip: If you use the new-string argument in the call to the PRXCHANGE routine, then old-string is not modified.

result-length

  • is a numeric variable that specifies the number of characters that are copied into the result.

  • Tip: Trailing blanks in the value of old-string are not copied to new-string , and are therefore not included as part of the length in result-length .

truncation-value

  • is either 0 or 1, depending on the result of the change operation:

    if the entire replacement result is not longer than the length of new-string .

    1

    if the entire replacement result is longer than the length of new-string .

number-of-changes

  • is a numeric variable that specifies the total number of replacements that were made. If the result is truncated when it is placed into new-string , the value of number-of-changes is not changed.

Details

The CALL PRXCHANGE routine matches and replaces a pattern. If the value of times is -1, the replacement is performed as many times as possible.

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

Comparisons

The CALL PRXCHANGE routine is similar to the PRXCHANGE function except that the CALL routine returns the value of the pattern matching replacement as one of its parameters instead of as a return argument.

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 replaces all occurrences of cat, rat, or bat with the value TREE.

 data _null_;        /* Use a pattern to replace all occurrences of cat,      */        /* rat, or bat with the value TREE.                      */     length text $ 46;     RegularExpressionId = prxparse('s/[crb]at/tree/');     text = 'The woods have a bat, cat, bat, and a rat!';        /* Use CALL PRXCHANGE to perform the search and replace. */        /* Because the argument  times  has a value of -1, the   */        /* replacement is performed as many times as possible.   */     call prxchange(RegularExpressionId, -1, text);     put text;  run; 

SAS writes the following line to the log:

 The woods have a tree, tree, tree, and a tree! 

See Also

Functions and CALL routines:

  • 'CALL PRXDEBUG Routine' on page 356

  • 'CALL PRXFREE Routine' on page 358

  • 'CALL PRXNEXT Routine' on page 359

  • 'CALL PRXPOSN Routine' on page 361

  • 'CALL PRXSUBSTR Routine' on page 364

  • '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