With skip sequential access,
the initial record of a series is located with keyed direct access.
(VSAM does not permit skip sequential addressed 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 key of the
first record that you want but do not know (or do not want to specify)
the key of subsequent records.
Use the SKIP option
in the INFILE statement to specify skip sequential processing. Retrieve
the first record directly by specifying the key of the record that
you want with the KEY= option in the INFILE statement. When you use
the SKIP option, leaving the value of the KEY= variable
unchanged turns off direct access and indicates that
subsequent records are to be retrieved with sequential access. If
you need to know the key of subsequent KSDS records, you can read
it from the record itself, because the key is part of the record.
The following sample program illustrates
skip sequential retrieval and generic key processing. The program
reads in the generic portion of the key, reads all of the records
in the KSDS data set with that generic key, and then writes them on
the procedure output file. Note that the SKIP option retrieves only
the first record with a key matching the KEY= variable. You must
supply statements to read additional records.
When processing skip
sequentially, remember that you must end the DATA step with a SET
or a STOP statement. In the example program below, end-of-file sets
the feedback code to 4, and the IF RC=4 clause stops the DATA step.
If there is no record with the generic key specified, the FEEDBACK=
variable is set to 16, a message is printed, and the next observation
is processed.
data keys;
length keyvar keyword1 $1;
input keyvar $;
cards;
1
5
8
;
data process;
set keys;
file print;
if _n_=1 then do;
put 'The KSDS records selected by GENKEY and SKIP are: ';
put;
end;
/* Read all the records with the value of KEYVAR in the key. */
/* Set KEY= variable for generic skip sequential processing. */
infile myksds vsam key=keyvar genkey skip feedback=sasrc keypos=kp;
input @;
/* Stop if end-of-file. */
if sasrc=4 | sasrc=16 then do;
_error_=0;
if sasrc=4 then stop;
/* If there is no record with this generic key, print a */
/* message to the procedure output file, and go on to the next */
/* observation. */
else do;
sasrc =0;
put 'There is no record with this generic key: ' keyvar;
return;
end;
end;
/* Retain the value of KEYVAR to compare the first word of the */
/* key of records read with sequential access. Initialize the */
/* value of KEYWORD1 to the KEYVAR value to start the loop. */
input @ kp keyword1 $;
/* Sequentially read while the first word of the key matches */
/* the value of KEYVAR. Write the records to the SAS print */
/* file. */
do while (keyword1 eq keyvar);
put _infile_;
input @;
/* Stop if end-of-file. */
if sasrc=4 | sasrc=16 then do;
_error_=0;
if sasrc=4 then stop;
/* If there is no record with this generic key, print a */
/* message to the procedure output file, and go on to the next */
/* observation. */
else do;
sasrc=0;
put 'There is no record with this generic key: ' keyvar;
return;
end;
end;
input @ kp keyword1 $;
end;
run;