FETCH Function


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

Category: SAS File I/O

Syntax

FETCH ( data-set-id <,'NOSET'>)

Arguments

data-set-id

  • specifies the data set identifier that the OPEN function returns.

'NOSET'

  • prevents the automatic passing of SAS data set variable values to macro or DATA step variables even if the SET routine has been called.

Details

FETCH returns a 0 if the operation was successful, ‰  0 if it was not successful, and - 1 if the end of the data set is reached. FETCH skips observations marked for deletion.

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 so that fetched values are not automatically copied to the DATA step or macro variables, use the NOSET option.

Examples

This example fetches the next observation from the SAS data set MYDATA. If the end of the data set is reached or if an error occurs, SYSMSG retrieves the appropriate message and writes it to the SAS log. Note that in a macro statement you do not enclose character strings in quotation marks.

 %let dsid=%sysfunc(open(mydata,i));  %let rc=%sysfunc(fetch(&dsid));  %if &rc ne 0 %then    %put %sysfunc(sysmsg());  %else     %do;  ...more macro statements...  %end;  %let rc=%sysfunc(close(&dsid)); 

See Also

CALL Routine:

  • 'CALL SET Routine' on page 393

Functions:

  • 'FETCHOBS Function' on page 524

  • '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