Functions and CALL Routines |
Category: | SAS File I/O |
Syntax | |
Arguments | |
Details | |
Examples | |
See Also |
Syntax |
FETCHOBS(data-set-id,obs-number<,options>) |
is a numeric variable that specifies the data set identifier that is returned by the OPEN function.
is a numeric constant, variable, or expression that 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 number might 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. |
is a character constant, variable, or expression that names one or more options, separated by blanks:
Details |
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 non-zero 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.
Examples |
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());
See Also |
| |||||||
|
Copyright © 2011 by SAS Institute Inc., Cary, NC, USA. All rights reserved.