Working with SAS Data Sets


Delete Observations

Use the DELETE statement to mark an observation for subsequent deletion. The general form of the DELETE statement is as follows:

  • DELETE <range> <WHERE(expression)> ;

where

range

specifies a range of observations. For details, see the section Process a Range of Observations.

expression

is an expression that is evaluated as being true or false. For details about the WHERE clause, see the section Process Data by Using the WHERE Clause.

The DELETE statement marks observations for deletion. To actually delete the marked observations and renumber the remaining observations, use the PURGE statement .

Suppose the student named John has moved and you want to delete the corresponding observation from the Class data set, which was created in the section Edit a SAS Data Set. The following statements find the observation for John and mark it for deletion:

edit Class;
find all where(name={'John'}) into Obs;
delete point Obs;

To update the data set and renumber the observations, use the PURGE statement. Be aware that the PURGE statement deletes any indexes associated with a data set.

purge;
show contents;

Figure 7.17: Updated Data Set

DATASET : WORK.CLASS.DATA                                                       
                                                                                
 VARIABLE                          TYPE  SIZE                                   
 --------------------------------  ----  ----                                   
 Name                              char     8                                   
 Sex                               char     1                                   
 Age                               num      8                                   
 Height                            num      8                                   
 Weight                            num      8                                   
                                                                                
Number of Variables   : 5                                                       
Number of Observations: 18                                                      
                                                                                



The data set now has 18 observations, whereas it used to have 19.