Previous Page | Next Page

Processing an RRDS in a SAS Job

Updating Records in an RRDS

To update records in an RRDS, complete the following 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 that is being modified. You must first retrieve the record sequentially or by direct access using the RRN= option before you can update the data set.

  4. Use the PUT statement to write the complete record.

For a list of the options that you can use when you update records, see SAS Options for an RRDS.

When you update a record in an RRDS, input access for reading can be either sequential or direct. (For more information, see Access Types for RRDS Operations). Access is sequential unless the RRN= direct access option is specified in the INFILE statement. Sequential access in an RRDS means in relative-record order. You can use a combination of direct and sequential access to the input data set if you specify the SKIP option in the INFILE statement. For more information, see Reading an RRDS with Skip Sequential Access.

When you update an RRDS record, you must include a 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 easier 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;

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 that are retrieved need to be updated. For more information, see Using the UPDATE= Option. In the following example, the RRDS records are read sequentially without being retrieved for update until the IF clause condition is met. When the IF condition is true (in this case, IDNUM=15), the UPDATE= variable is set to 1, and the record is retrieved again with update access.

data rrnumbrs;

     /* Use the IDNUM variable to select the RRNs of */
     /* records to process.                          */
   infile myrrds vsam;
   input;
   idnum = _rrn_;
run;

data six;
   set rrnumbrs;
   updtevar =0;
   infile myrrds vsam rrn=idnum update=updtevar;
   input;
   if (idnum=15) then do;
      updtevar=1;
      input;

       /* Create the NEWDATA variable which contains */
       /* the update data.                           */
       newdata=36;

      file myrrds vsam;
      put @ 1 _infile_ @88 newdata;
   end;
run;

Previous Page | Next Page | Top of Page