Erasing Records from a VSAM Data Set

Erasing a record involves both input access (because the record must be read first) and output access. You can erase records from a KSDS or an RRDS. The record must be retrieved before you can erase it, and you must specify the VSAMUPDATE System Option. VSAM imposes a restriction that ESDS records cannot be erased.
You must use an INFILE statement and an INPUT statement to read the record and a FILE statement and a PUT statement to erase the record from a VSAM data set. Of course, the INFILE and FILE statements must have the same fileref. That is, they must reference the same data set. You must use the ERASE= option in the INFILE statement to specify a numeric SAS variable that tells SAS whether a record is to be erased.
  • When you set the ERASE= variable to a value of 1 before a PUT statement for the data set executes, the record is erased.
    After the PUT statement executes, the ERASE= variable is automatically reset to 0. Therefore, you must set it to 1 again 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 statement for the data set executes, the record is updated with the data specified instead of being erased. This is the default action that is taken if the ERASE= option is not specified.