Reads a specified observation from a SAS data set into the Data
Set Data Vector (DDV) and returns a value
FETCHOBS(data-set-id,obs-number<,options>)
|
- data-set-id
- specifies the data set identifier that the
OPEN function returns.
- obs-number
- specifies the number of the observation
to read. FETCHOBS treats the observation value as a relative observation number
unless you specify the ABS option. The relative observation numbert may or
may not coincide with the physical observation number on disk, because the
function skips observations marked for deletion. When a WHERE clause is active,
the function counts only observations that meet the WHERE condition.
Default: |
FETCHOBS skips deleted
observations. |
- options
- names one or more options, separated by
blanks and enclosed in quotation marks:
'ABS' |
specifies that the value of obs-number is absolute; that is, deleted observations are
counted. |
'NOSET' |
prevents the automatic passing of
SAS data set variable values to DATA step or macro variables even if the SET
routine has been called. |
FETCHOBS returns
0 if the operation was successful, 0 if it was not successful, and -1
if the end of the data set is reached. To retrieve the error message that
is associated with a nonzero return code, use the SYSMSG function. If the
SET routine has been called previously, the values for any data set variables
are automatically passed from the DDV to the corresponding DATA step or macro
variables. To override this behavior temporarily, use the NOSET option.
If obs-number is less than
1, the function returns an error condition. If obs-number
is greater than the number of observations in the SAS data set, the function
returns an end-of-file condition.
This example fetches the tenth observation from the
SAS data set MYDATA. If an error occurs, the SYSMSG function retrieves the
error message and writes it to the SAS log. Note that in a macro statement
you do not enclose character strings in quotation marks.
%let rc = %sysfunc(fetchobs(&mydataid,10));
%if &rc = -1 %then
%put End of data set has been reached.;
%if &rc > 0 %then %put %sysfunc(sysmsg());
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.