Processing a KSDS in a SAS Job |
To erase a record from a KSDS, complete the following steps:
specify the VSAMUPDATE system option.
Use an INFILE statement and an INPUT statement to read the record and a FILE statement and a PUT statement to erase the record. Of course, the INFILE statement and FILE statement must have the same fileref; they must reference the same data set.
Specify the key that you want to erase with the KEY= 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.
See SAS Options for a KSDS for a list of the options that you can use to erase records. 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 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 a KSDS, you must copy the key of the record to the PUT buffer by issuing an _INFILE_ argument in the PUT statement 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 to erase another record. This prevents you from inadvertently deleting 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 that is specified instead of being erased. This is the default action taken if you do not use the ERASE= option.
In the following example, the variable SASKEY in the SAS data set KEYS contains the keys 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 eleven; set keys; erasevar=1; infile myksds vsam key=saskey erase=erasevar; file myksds vsam; input; if (saskey eq '547392749') then do; put _infile_; end; run;
Copyright © 2008 by SAS Institute Inc., Cary, NC, USA. All rights reserved.