Functions and CALL Routines |
Category: | Character String Matching |
Restriction: | Use with the PRXPARSE function. |
Syntax | |
Arguments | |
Details | |
Comparisons | |
Examples | |
Example 1: Extracting First and Last Names | |
Example 2: Extracting Names When Some Names Are Invalid | |
See Also |
Syntax |
PRXPOSN(regular-expression-id, capture-buffer, source) |
specifies a numeric variable with a value that is a pattern identifier that is returned by the PRXPARSE function.
is a numeric constant, variable, or expression that identifies the capture buffer for which to retrieve a value:
If the value of capture-buffer is zero, PRXPOSN returns the entire match.
If the value of capture-buffer is between 1 and the number of open parentheses in the regular expression, then PRXPOSN returns the value for that capture buffer.
If the value of capture-buffer is greater than the number of open parentheses, then PRXPOSN returns a missing value.
Details |
The PRXPOSN function uses the results of PRXMATCH, PRXSUBSTR, PRXCHANGE, or PRXNEXT to return a capture buffer. A match must be found by one of these functions for PRXPOSN to return meaningful information.
A capture buffer is part of a match, enclosed in parentheses, that is specified in a regular expression. This function simplifies using capture buffers by returning the text for the capture buffer directly, and by not requiring a call to SUBSTR as in the case of CALL PRXPOSN.
For more information about pattern matching, see Pattern Matching Using Perl Regular Expressions (PRX).
Comparisons |
The PRXPOSN function is similar to the CALL PRXPOSN routine, except that it returns the capture buffer itself rather than the position and length of the capture buffer.
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 uses PRXPOSN to extract first and last names from a data set.
data ReversedNames; input name & $32.; datalines; Jones, Fred Kavich, Kate Turley, Ron Dulix, Yolanda ; data FirstLastNames; length first last $ 16; keep first last; retain re; if _N_ = 1 then re = prxparse('/(\w+), (\w+)/'); set ReversedNames; if prxmatch(re, name) then do; last = prxposn(re, 1, name); first = prxposn(re, 2, name); end; run; options pageno=1 nodate ls=80 ps=64; proc print data = FirstLastNames; run;
Output from PRXPOSN: First and Last Names
The SAS System 1 Obs first last 1 Fred Jones 2 Kate Kavich 3 Ron Turley 4 Yolanda Dulix
The following example creates a data set that contains a list of names. Observations that have only a first name or only a last name are invalid. PRXPOSN extracts the valid names from the data set, and writes the names to the data set NEW.
data old; input name $60.; datalines; Judith S Reaveley Ralph F. Morgan Jess Ennis Carol Echols Kelly Hansen Huff Judith Nick Jones ; data new; length first middle last $ 40; keep first middle last; re = prxparse('/(\S+)\s+([^\s]+\s+)?(\S+)/o'); set old; if prxmatch(re, name) then do; first = prxposn(re, 1, name); middle = prxposn(re, 2, name); last = prxposn(re, 3, name); output; end; run; options pageno=1 nodate ls=80 ps=64; proc print data = new; run;
The SAS System 1 Obs first middle last 1 Judith S Reaveley 2 Ralph F. Morgan 3 Jess Ennis 4 Carol Echols 5 Kelly Hansen Huff
See Also |
|
Copyright © 2011 by SAS Institute Inc., Cary, NC, USA. All rights reserved.