PRXPOSN Function

Returns a character string that contains the value for a capture buffer.

Category: Character String Matching
Restriction: Use with the PRXPARSE function.


Required Arguments


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.


specifies the text from which to extract capture buffers.


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) .


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 SAS Functions and CALL Routines by Category.


Example 1: Extracting First and Last Names

The following example uses PRXPOSN to extract first and last names from a data set.
data ReversedNames;
   input name & $32.;
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 
         last = prxposn(re, 1, name);
         first = prxposn(re, 2, name);
proc print data = FirstLastNames;
Output from PRXPOSN: First and Last Names
Output from PRXPOSN: First and Last Names

Example 2: Extracting Names When Some Names Are Invalid

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.;
Judith S Reaveley
Ralph F. Morgan
Jess Ennis
Carol Echols
Kelly Hansen Huff
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
         first = prxposn(re, 1, name);
         middle = prxposn(re, 2, name);
         last = prxposn(re, 3, name);
proc print data = new;
Output of Valid Names
Output of Valid Names