DELETE Statement

DELETE <range> <WHERE(expression)> ;

The DELETE statement marks observations (also called records) in the current output data set for deletion. To actually delete the records and renumber the remaining observations, use the PURGE statement.

The arguments to the DELETE statement are as follows:

range

specifies a range of observations.

expression

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

You can specify range by using a keyword or by using the POINT operand to specify an observation number. The following keywords are valid values for range:

ALL

specifies all observations.

CURRENT

specifies the current observation.

NEXT <number>

specifies the next observation or the next number of observations.

AFTER

specifies all observations after the current one.

POINT value

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

Value

Example

a single record number

delete point 5

a literal that contains several

delete point {2 5 10}

record numbers

 

the name of a matrix that

p=5; delete point p;

contains record numbers

 

an expression in parentheses

delete point (p+1);

The default value for range is CURRENT. If the current data set has an index in use (see the INDEX statement, the POINT keyword 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 ;

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.

The operand argument in a WHERE comparison can be a matrix. For the following operators, the WHERE clause succeeds if any of the elements in the matrix satisfy the condition:

 

=,   ?,   = :,   = *

For the remaining operators, the WHERE clause succeeds provided that all the elements in the matrix satisfy the condition.

Logical expressions can be specified within the WHERE clause by using the AND (&) and OR (|) operators. If clause is a valid WHERE expression, then you can combine expressions as follows:

 

Both conditions satisfied

 

clause1 & clause2

 

Either condition satisfied

 

clause1 | clause2

The following statements show examples of using the DELETE statement:

proc iml;
/* create sample data set */
sex = { M,  M,  M,  F,  F,  F};
age = {34, 28, 38, 32, 24, 18};
create MyData var {"Sex" "Age"};
append;
close MyData;

/* delete observations in data set */
edit MyData;
delete;                     /* marks the current obs  */
delete point 3;             /* marks obs 3            */
delete all where(age<21);   /* marks obs where age<21 */
purge;                      /* deletes all marked obs */
close MyData;

proc print data=MyData;
run;

Figure 23.84 Observations That Remain after Deletion
Obs Sex Age
1 M 28
2 F 32
3 F 24

Notice that observations marked for deletion by using the DELETE statement are not physically removed from the data set until a PURGE statement is executed.