You
can use the FEEDBACK= option to test whether the relative-record slot
that is specified by RRN= is empty. You can then either update or
add a record based on the value of the FEEDBACK= variable. The FEEDBACK=
option specifies a SAS variable that is set to the VSAM logical error
code when a logical error occurs. (See
Error-Handling Techniques and Error Messages for more information.)
The following is the
general slot-testing technique using the FEEDBACK= and RRN= options
and the INPUT statement:
-
When the FEEDBACK= variable is
0 after the INPUT statement executes, the record that is in the slot
specified by RRN= has been read into the input buffer.
Execute a PUT statement
in order to
update the record.
-
When the FEEDBACK= variable is
16 after the INPUT statement executes, the slot that is specified
by RRN= is empty.
Reset the FEEDBACK=
and _ERROR_ variables to 0, and execute a PUT statement in order
to
add the PUT buffer data as a new record
in this slot.
data rrdsinfo;
/* Select values for lastname, firstname, and class. */
length lastname $10 frstname $10 class $2;
input id lastname frstname class;
datalines;
15 FLINTSTONE FRED SE
30 RUBBLE BARNEY SO
31 FLINTSTONE WILMA SE
32 RUBBLE BETTIE SO
;
data nine;
set rrdsinfo;
infile myrrds vsam feedback=fdbk rrn=id;
/* Read the relative-record number to be updated. */
input;
file myrrds vsam;
/* If the FEEDBACK= variable indicates that the relative */
/* record slot number is empty, reset the FDBK and */
/* _ERROR_ variables to 0, and write a new record. */
if fdbk=16 then do;
fdbk=0;
_error_=0;
put @10 lastname $10.
@20 frstname $10.
@86 class $2.;
/* If the FEEDBACK= variable indicates PUT for update */
/* without previous INPUT then reset the FDBK and */
/* _ERROR_ variables to 0, and write the new record. */
if fdbk=92 then do;
fdbk=0;
_ERROR_=0;
put @10 lastname $char10.
@20 frstname $char10.
@86 class $char2.;
end;
end;
/* If the record exists, update the class field. */
else do;
put _infile_ @86 class;
end;
run;