FETCHOBS Function


FETCHOBS Function

Reads a specified observation from a SAS data set into the Data Set Data Vector (DDV)

Category: SAS File I/O

Syntax

FETCHOBS ( data-set-id , obs-number < ,options >)

Arguments

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 number 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.

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

CALL Routine:

  • 'CALL SET Routine' on page 393

Functions:

  • 'FETCH Function' on page 523

  • 'GETVARC Function' on page 572

  • 'GETVARN Function' on page 573




SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3
SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 704

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net