Operations on VSAM Data Sets in SAS Programs

SAS programs handle VSAM data sets the same as any external data set. The following are examples of operations that SAS can perform on external data sets, which are data sets that are not created by SAS:
  • The VSAM data set can be read in a DATA step. Information from the VSAM data set can be used to create a SAS data set if appropriate for the application.
  • The VSAM data set can be updated in a DATA step by adding new records or by modifying or erasing existing records.
  • A SAS data set can be created from a VSAM data set. You can manipulate this data set with SAS DATA steps or procedures and then use it to update the VSAM data set in a subsequent DATA step.
  • You can use a DATA step to generate a SAS data view of the VSAM data set.
The following figure illustrates a typical SAS DATA step processing a VSAM data set. A VSAM external data set is shown as input to a SAS DATA step. Only the INFILE statement with some of the most common special SAS options and the FILE statement are shown. Notice that both the INFILE and FILE statements specify the VSAM option and the fileref that refers to the VSAM data set. The RBA=, KEY=, and RRN= direct access variables are shown as INFILE statement options that depend on whether the VSAM data set is an ESDS, a KSDS, or an RRDS. (You do not need to specify a direct access option to process the data set sequentially.) The FEEDBACK= variable is specified in the INFILE statement. Remember that you would need both an INPUT and a PUT statement to read and update the VSAM data set.
Processing VSAM data Sets in SAS Programs
Processing VSAM data Sets in SAS Programs
You can perform five general types of operations on VSAM data sets in SAS programs:
  • read records from an existing data set. All VSAM data set types can be read both sequentially and with one or more direct access modes.
  • add new records to an existing VSAM data set.
  • update an existing record by retrieving, modifying, and then writing it back to the data set. Note that the record must be retrieved before being updated.
  • erase an existing record from an RRDS or a KSDS. The record must be retrieved before erasing it. Records cannot be erased from an ESDS.
  • load new records into a new VSAM data set. This operation is discussed separately in Defining and Loading a VSAM Data Set.
When you perform these operations, you can use certain types of access with each data set type. See the following table for an outline of this information. Note that VSAM provides both sequential and some form of direct access for each data set type.
Supported VSAM Operations and Access Types
Operation
Access Type
ESDS
KSDS
RRDS
Read
Sequential:
Yes
Yes
Yes
Direct access by:
Key
No
Yes
No
Generic key
No
Yes
No
RBA
Yes
Yes
No
RRN
No
No
Yes
Skip sequential:
No
Yes
Yes
Update
Sequential:
Yes
Yes
Yes
Direct access by:
Key
No
Yes
No
RBA
Yes
Yes
No
RRN
No
No
Yes
Add or Load
Sequential:
Yes
Yes
Yes
Direct access by:
Key
No
Yes
No
RBA
No
No
No
RRN
No
No
Yes
Erase
Sequential:
No
Yes
Yes
Direct access by:
Key
No
Yes
No
RBA
No
Yes
No
RRN
No
No
Yes