Reading Records from an ESDS

Access Types for ESDS Operations

You can use sequential or addressed direct access to read records from an ESDS within a SAS program. If the ESDS has an alternate key index, you can also use keyed direct access. (See Keyed Direct Access by Alternate Keys.) The options that are specified in the INFILE statement determine the access type for an ESDS read operation. Either the VSAMLOAD System Option or theVSAMUPDATE System Option must be specified in order to read VSAM data sets.
Access Types for ESDS Operations
Operation
Read
(INFILE/INPUT Statements)
Write
(FILE/PUT Statements)
Read
Sequential
Does not apply
Direct with RBA= option
Add*
Sequential with RBA= and SEQ options
Sequential: records are always added to the end of file
Direct with RBA= option
Update
Sequential
Direct with RBA= option
Direct: the last record read is the record updated
Load
Does not apply
Sequential: in entry order
* The INPUT statement is not required.

Reading an ESDS with Sequential Access

In an ESDS, sequential means in entry order. By default, the records that are in the data set are read from the beginning to the end of the data set. The following example shows the DATA step that you can use to read an ESDS sequentially:
/* Read data from an ESDS into a SAS data set   */

data one;
   infile myesds vsam; 
   input;
   ...more SAS statements...
If you specify the BACKWARD option, the data set is read backward, from the last record to the first record.

Reading an ESDS with Direct Access

Addressed Direct Access by RBA

When an ESDS is read with addressed direct access, records are retrieved directly by the address relative to the beginning of the data set (relative-byte address). For this type of access to be useful, you must know the RBAs of the records that you want to access. You might know the RBA if it has some relationship to the record contents or if you have obtained it (for example, from the _RBA_ automatic variable in a previous SAS DATA step).
To use addressed direct access, specify the RBA= option in the INFILE statement for the VSAM data set that is to be accessed by RBA. The RBA= option defines a variable whose value must be set to the RBA of the logical record or control interval to be retrieved by an INPUT statement. The address that you specify must correspond to the beginning of a data record (logical record or control interval). Otherwise, the request is invalid and causes a VSAM logical error.
The following program illustrates addressed direct access to an ESDS:
data one;
   infile myesds vsam;
   input;
   rbanum =_rba_;
   keep rbanum;
run;

data two;
   set one;
   infile myesds vsam rba=rbanum;
   input;
   ...more SAS statements...

Keyed Direct Access by Alternate Keys

If there is an alternate key index for an ESDS, you can use keyed direct access by alternate keys to read an ESDS. An alternate index is created outside the SAS environment by using IBM Access Method Services. Then the ESDS records can be accessed directly by key, in a manner similar to a KSDS. For instructions on how to create an alternate index for an ESDS, see Using Alternate Indexes for VSAM Data Sets.
You can treat an ESDS accessed through an alternate index as if it were a KSDS, except that records cannot be erased and the record length cannot be changed.
The following table summarizes the type of access that you can use for an ESDS with an alternate key index.
Operations on an ESDS with an Alternate Index
Operation
Access
Read
Sequential
Direct by:
  • alternate key
  • RBA
Add
Sequential
Update
Sequential
Direct by:
  • alternate key, if required
  • RBA
Load
Sequential