r_position(C;S;X)

Returns the index of the first column in a given set of columns that matches a specified value.

Function type

Vector only

Syntax

r_position(C;S;X)

Input

Argument Type Description
C any A space- or comma-separated list of column names

C may also be a string expression (in single quotes) constituting a pattern for matching columns. For instance, 'foo*' specifies all columns that begin with "foo".

If C is omitted, the values in all of the columns are included.

Note: The columns specified by C must be either all numeric (integer and decimal) or all text.
S integer A boolean column or an expression in rcv_/rcn_/rct_ which determines whether or not that column is selected to be included in the calculation. See System variables for more information about rcv_/rcn_/rct_.

If S is omitted, all columns will be considered by the function (subject to any prior column selections).

X any A scalar value or the name of a column

If X is omitted, an error is returned.

Return Value

For each row of the table, r_position returns an integer value that represents the index within the group of columns specified by C of the first column that has the value X.

For instance, if the value X appears in the third column and the fifth column of the group of columns specified, the result will be 3.

If X does not match the type of the columns specified by C (i.e., numeric or text), an error is returned.

If there is no match, the result is N/A.

Sample Usage

c1 c2 c3 c4 na_val r_position(;;c1) r_position(c1 c3;;7) r_position(c2 c3 c4;;c1) r_position(c2 c3 c4;;na_val)
2 5 7 2 NA 1 2 3 NA
7 7 4 1 NA 1 1 1 NA
NA 0 9 3 NA 1 NA NA NA
NA NA NA NA NA 1 NA 1 1