Erasing Records from an RRDS

To erase a record from an RRDS, complete the following steps:
  1. Use an INFILE statement and an INPUT statement to read the record and a FILE statement and a PUT statement to erase the record. The INFILE statement and FILE statement must have the same fileref; they must reference the same data set.
  2. Specify the record that you want to erase with the RRN= option and the ERASE= option in the INFILE statement. The ERASE= option specifies a numeric SAS variable that tells SAS whether a record is to be erased.
The following list explains which values you can set for the ERASE= option as well as what the values specify:
  • When you set the ERASE= variable to a value of 1 before a PUT statement for the data set that executes, the record is erased. Notice that the record is not updated with the data in the PUT statement; it is erased instead. However, for an RRDS, you must still copy the relative-record number of the record to the PUT buffer by issuing an _INFILE_ argument in the PUT statement in order to identify the record.
    After a record is erased, the ERASE= variable is automatically reset to 0. Therefore, you must set it to 1 again in order to erase another record. This prevents the inadvertent deletion of a series of records.
  • When you set the ERASE= variable to a value of 0 before a PUT for the data set executes, the record is updated with the data that is specified instead of being erased. This is the default action taken if the ERASE= option is not used.
In the following example, the variable RRNVAR in the SAS data set ERASEREC contains the RRNs of the records that you want to erase. Notice that the PUT statement erases the record rather than updating it, because the ERASE= variable, ERASEVAR, is set to a value of 1.
data seven;
   set rrnumbrs;
   erasevar=1;
   infile myrrds vsam rrn=rrnvar erase=erasevar;
   file myrrds vsam;
   input;
   put _infile_;
run;