Previous Page | Next Page

Processing an ESDS in a SAS Job

Updating Records in an ESDS


Steps for Updating Records in an ESDS

To update records in an ESDS, follow these steps:

  1. Specify the VSAMUPDATE system option.

  2. Include both an INFILE and a FILE statement for the data set. Specify the VSAM option in both the INFILE and the FILE statements. Specify all other necessary options in the INFILE statement, which must precede the FILE statement.

  3. Use an INPUT statement to read the record being modified.

  4. Use the PUT statement to write the complete record. An INPUT statement brings the record into the INPUT buffer but does not copy it to the PUT buffer. This enables you to change the record easily.

For a list of options that you can use to update records in an ESDS, see SAS Options for an ESDS.

When records in an ESDS are updated, you have the following input and output access:


Using the PUT Statement When Updating Records in an ESDS

When you update an ESDS record, you must use the PUT statement to write the complete record. There are two common ways of writing the record with the PUT statement:

The latter method is the easiest for most applications. The following statement copies the last record that is read into the PUT buffer and overlays the information starting in columns 10 and 30 with the values in NEWDATA1 and NEWDATA2:

   PUT @  1 _INFILE_
       @ 10 NEWDATA1
       @ 30 NEWDATA2;

In most cases, when a record is retrieved for update, no user, including you, can access that particular record or any other records in the same control interval. Use the UPDATE= option to avoid user lockout when only a few of the records retrieved need to be updated. See Using the UPDATE= Option for more information.

In the following example, the RBAs of records are captured and stored in a SAS variable called RBAVAR from the _RBA_ automatic variable. In the next DATA step, the records are then read without being retrieved for update until the condition specified in the IF clause is met. When the IF condition is true (RBANUM=1260), the record is retrieved again with update access.

data rbas;
   infile myesds vsam ;
   input;
   rbanum=_rba_ ;
   keep rbanum;
run;

data esdsupdt;
   set rbas;
   updtevar=0;
   infile myesds vsam rba=rbanum update=updtevar;
   input;
   if (rbanum=1260) then do;
      updtevar=1;
      input;

         /* Create NEWDATA */
      lastname='Flintstone ';
      frstname='Fred      ';
      file myesds vsam ;
      put @1 _infile_
          @10 lastname
          @20 frstname;
   end;
run;

Previous Page | Next Page | Top of Page