Previous Page | Next Page

Functions and CALL Routines

CALL PRXCHANGE Routine



Performs a pattern-matching replacement.
Category: Character String Matching
Restriction: Use with the PRXPARSE function.
Interaction: When invoked by the %SYSCALL macro statement, CALL PRXCHANGE removes the quotation marks from its arguments. For more information, see Using CALL Routines and the %SYSCALL Macro Statement.

Syntax
Arguments
Details
Comparisons
Examples
See Also

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 variable with a value that is a pattern identifier that is returned from the PRXPARSE function.

times

is a numeric constant, variable, or expression 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 with a return value that is 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 a numeric variable with a returned value that is either 0 or 1, depending on the result of the change operation:

0

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 with a returned value that is 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 Perl Regular Expressions (PRX).


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.


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

CALL PRXFREE Routine

CALL PRXNEXT Routine

CALL PRXPOSN Routine

CALL PRXSUBSTR Routine

PRXCHANGE Function

PRXPAREN Function

PRXMATCH Function

PRXPARSE Function

PRXPOSN Function

Previous Page | Next Page | Top of Page