| Functions and CALL Routines |
| Category: | Character String Matching |
| Restriction: | Use with the PRXPARSE function. |
| 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>>>>); |
specifies a numeric pattern identifier that is returned from the PRXPARSE function.
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. |
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. |
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. |
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. |
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. |
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).
| 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: |
Copyright © 2007 by SAS Institute Inc., Cary, NC, USA. All rights reserved.