Language Reference

FIND Statement

finds observations

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

The inputs 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.
The FIND statement finds the observation numbers of records 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.

You can specify a range of observations with a keyword or by record number using the POINT option. You can use any of the following keywords to specify range:


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 operand
observations specified by number, where operand is one of the following.

Operand Example
a single record numberpoint 5
a literal giving severalpoint {2 5 10}
record numbers 
the name of a matrixpoint p
containing record numbers 
an expression in parenthesespoint (p+1)

If the current data set has an index in use, 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)

In the preceding statement,
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;
 
p and {p2} are column vectors containing the observation numbers that satisfy the WHERE clause in the given range. The default range is all observations.

Previous Page | Next Page | Top of Page