Chapter Contents
Chapter Contents
Language Reference

DELETE Statement

marks observations for deletion

DELETE <range> <WHERE(expression)>;

The inputs to the DELETE statement are as follows:
specifies a range of observations.

is an expression that is evaluated for being true or false.
Use the DELETE statement to mark records for deletion in the current output data set. To delete records and renumber the remaining observations, use the PURGE statement.

You can specify range by using a keyword or by record number using the POINT operand. The following keywords are valid values for range:
specifies all observations.
specifies the current observation.
NEXT <number>
specifies the next observation or the next number of observations.
specifies all observations after the current one.
POINT operand
specifies observations 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)
CURRENT is the default value for range. If the current data set has an index in use, the POINT option is invalid.

The WHERE clause conditionally selects observations that are contained within the range specification. The general form of the WHERE clause is

WHERE( variable comparison-op operand)

In the statement above,
is a variable in the SAS data set.

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 similar to a given string

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 conditon:

 ^=   ^?   <   <=   >   >=

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 using the AND (&) and OR (|) operators. The general form is

 clause&clause (for an AND clause)
 clause|clause (for an AND clause)

where clause can be a comparison, a parenthesized clause, or a logical expression clause that is evaluated 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.

Here are several examples of DELETE statements:

   delete;                     /* deletes the current obs  */
   delete point 34;            /* deletes obs 34           */
   delete all where(age<21);   /* deletes obs where age<21 */
You can use the SETOUT statement with the DELETE statement as follows:

   setout class point 34;     /* makes CLASS current output */
   delete;                    /* deletes ob 34              */
Observations deleted using the DELETE statement are not physically removed from the data set until a PURGE statement is issued.

Chapter Contents
Chapter Contents

Copyright © 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.