FIND Statement

FIND <range> <WHERE(expression)> INTO matrix-name ;

The FIND statement finds the observation numbers in range that satisfy the conditions of the WHERE clause. The FIND statement places these observation numbers in the numeric matrix whose name follows the INTO keyword.

The arguments to the FIND statement are as follows:

range

specifies a range of observations.

expression

is an expression that is evaluated for being true or false.

matrix-name

names a matrix to contain the observation numbers.

You can use any of the following keywords to specify the range of observations:

ALL

all observations

CURRENT

the current observation

NEXT <number>

the next observation or the next number of observations

AFTER

all observations after the current one

POINT value

observations specified by number, where value is one of the following:

Value

Example

A single record number

point 5

A literal that contains several

point {2 5 10}

record numbers

 

The name of a matrix

point p

that contains record numbers

 

An expression in parentheses

point (p+1)

If the current data set has an index in use (see the INDEX statement), the POINT option is invalid.

The WHERE clause conditionally selects observations, within the range specification, according to conditions given in the clause. The general form of the WHERE clause is

WHERE (variable comparison-op operand) ;

The arguments to the WHERE clause are as follows:

variable

is a variable in the SAS data set.

comparison-op

is one of the following comparison operators:

<

less than

<=

less than or equal to

=

equal to

>

greater than

>=

greater than or equal to

=

not equal to

?

contains a given string

?

does not contain a given string

= :

begins with a given string

= *

sounds like or is spelled like a given string

operand

is a literal value, a matrix name, or an expression in parentheses.

WHERE comparison arguments can be matrices. For the following operators, the WHERE clause succeeds if all the elements in the matrix satisfy the condition:

 

=   ?   <   <=   >   >=

For the following operators, the WHERE clause succeeds if any of the elements in the matrix satisfy the condition:

 

=   ?   = :   = *

Logical expressions can be specified within the WHERE clause by using the AND (&) and OR (|) operators. The general form is

 

clause & clause

(for an AND clause)

 

clause | clause

(for an OR clause)

where clause can be a comparison, a parenthesized clause, or a logical expression clause that is evaluated by using operator precedence.

Note: The expression on the left-hand side refers to values of the data set variables, and the expression on the right-hand side refers to matrix values.

Following are some valid examples of the FIND statement:

find all  where(name=:"Smith") into p;
find next where(age>30) into p2;

The column vectors p and p2 contain the observation numbers that satisfy the WHERE clause in the given range. The default range is all observations.