Previous Page | Next Page

Defining and Loading a VSAM Data Set

Loading Records into a VSAM Data Set


Loading Records into a New VSAM Data Set

VSAM does not allow you to process records while you are loading the data set. You can put the initial records into the data set, but you cannot read, update, or erase any of these records until the data set is closed. Because of this restriction, SAS requires you to use only a FILE statement, instead of both an INFILE and a FILE statement, for a VSAM data set that is to be loaded. You must also specify the VSAMLOAD system option. After the data set is loaded and closed, you can add, update, or erase records when the VSAMUPDATE system option is in effect.

You can read from and write to records in any other data set within the same DATA step that you use to load a VSAM data set. (For example, you can load a VSAM data set based on records you are processing from another data set.)

VSAM requires you to load a KSDS sequentially in key order. You can load an RRDS either sequentially in record order or directly by using the RRN= direct-access option in the FILE statement. An ESDS can be loaded only sequentially.


Options Used When Loading Records into a New VSAM Data Set

When you load initial records into a new VSAM data set, use only a FILE statement and specify the VSAMLOAD system option. In addition, you can use the following options in the FILE statement when you load a VSAM data set:

BUFND= KEYPOS= RECORDS=
BUFNI= LINE= RESET
COL= LINESIZE= RRN=
FEEDBACK= N= VSAM
KEYLEN= PASSWD=


Access Types When Loading Records into a VSAM Data Set

When you load records into a VSAM data set, access depends on the data set type:


Reloading a VSAM Data Set

If you plan to reload data sets into an existing VSAM data set in a DATA step, keep the following points in mind:

Data sets that have alternate indexes cannot be reloaded; they must be deleted, defined, and then loaded.


Loading a VSAM Data Set in a SAS DATA Step

The following example shows how to load a VSAM data set in a SAS DATA step. The data set is described in Sample STUDENT Data Set.

In the example, a previously defined ESDS is loaded in a SAS DATA step. The example also applies to a KSDS and an RRDS.

data load;
      /* Open a SAS data set for input. */
   set vsamdata.student;

      /* Open previously defined VSAM ESDS for output. */
   file myesds vsam;

      /* Write the data from the variable in the SAS data set to     */
      /* the appropriate column in a record of the ESDS.             */
   put @1  id       $9.   /* Student's Social Security number        */
       @10 lastname $10.  /* Student's surname                       */
       @20 frstname $10.  /* Student's given name                    */
       @30 address  $25.  /* Permanent mailing address               */
       @55 city     $15.  /* City of residence                       */
       @70 state    $2.   /* State of residence                      */
       @72 zip      $5.   /* Five-digit ZIP code                     */
       @77 balance  $5.   /* Balance from previous semester (if any) */
       @82 gpa      $4.   /* Grade point average on a 4.00 scale     */
       @86 class    $2.   /* FR, SO, JU, SE, or, GR                  */
       @88 hrs      $2.   /* Hours registered for in next semester   */
       @90 finaid   $1.;  /* Financial aid eligibility, Y or N       */
run;

Previous Page | Next Page | Top of Page