With skip sequential
access, the initial record of a series is located with keyed direct
access. After the first record is obtained, subsequent records are
retrieved sequentially. Skip sequential processing improves performance
because sequential retrieval requires less overhead and is faster
than direct retrieval. Skip sequential access is also useful when
you know the RRN of the first record that you want but do not know
(or do not want to specify) the RRN of subsequent records.
Use the SKIP option
in the INFILE statement to specify skip sequential processing. Retrieve
the first record directly by specifying the RRN of the record that
you want with the RRN= option in the INFILE statement. With the SKIP
option, leaving the value specified by the RRN= variable
unchanged turns off direct access and indicates that
subsequent records are to be retrieved with sequential access. The
relative-record number of each record that is retrieved is returned
in the _RRN_ automatic variable. The relative-record numbers might
not be consecutive, because some of the slots might be empty.
When you process skip
sequentially, you must specify a means of stopping the DATA step.
In the following example, end-of-file sets the feedback code to 4,
and the IF FDBK=4 clause stops the DATA step. Note that the SKIP option
retrieves only the one record with an RRN that matches the value of
the RRN= variable value. You must supply statements to read additional
records.
The following example
processes an RRDS skip sequentially. For meaningful output, this example
assumes that the data set was sorted by class before it was loaded.
The program reads in the RRNUMS data set, reads all the records in
the PROCESS data set that have those RRNs, and then writes them to
a procedure output file. Note that the SKIP option retrieves only
the records that are identified by the RRNs. You must supply statements
to read additional records. In the following example, the program
sequentially reads other records in the same class:
data rrnums;
input idnum class $;
cards;
0001 FR
0013 JU
0025 SO
;
run;
data process;
set rrnums;
file print;
if _n_=1 then do;
put 'The RRDS records selected skip sequentially are: ';
put;
end;
/* Get the first record wanted with direct access. */
infile myrrds vsam rrn=idnum skip feedback=fdbk;
input @;
/* Stop if the FEEDBACK= variable indicates end-of-file */
/* or if the RRN slot is empty or invalid. */
if fdbk=4 | fdbk=16 | fdbk=192 then do;
_error_=0;
if fdbk=4 then stop;
else do;
put 'RRN slot is empty, or invalid RRN. The feedback '
'code is ' fdbk ' and RRN is ' idnum;
fdbk =0;
return;
end;
end;
/* Read next records sequentially while the class matches. */
/* Write the records to the procedure output file. */
input @86 classnow $ 86-87;
do while (classnow=class);
put _infile_;
/* Stop if the FEEDBACK= variable indicates end-of-file */
/* or if the RRN slot is empty or invalid. */
if fdbk=4 | fdbk=16 | fdbk=192 then do;
_error_=0;
if fdbk=4 then stop;
else do;
put 'RRN slot is empty, or invalid RRN. The feedback '
'code is ' fdbk;
fdbk=0;
return;
end;
end;
input @86 classnow $ 86-87;
end;
run;
Access Types for RRDS Operations
|
(INFILE/INPUT Statements)
|
|
|
|
|
|
Skip sequential with
SKIP and RRN= options
|
|
|
Must be direct: use
the RRN= option
|
Sequential with SEQUENTIAL
and RRN= options
|
|
|
Direct: the record read
is the record updated
|
|
|
|
Direct: the record read
is the record erased
|
|
|
|
Sequential: in relative-record
order
|
|
|
1The INPUT statement is
not required.
|