Chapter Contents

Previous

Next
FETCHOBS

FETCHOBS



Reads a specified row from a SAS table into the Table Data Vector (TDV)

Category: SAS Table


Syntax
Details
Example
See Also

Syntax

sysrc=FETCHOBS(table-id,row-number<,options>);

sysrc
contains the return code for the operation:
0 successful
>0 not successful
<0 the operation was completed, but a warning or a note was generated. If the row is locked, it is still fetched (read in) but a sysrc of _SWNOUPD is returned.
-1 the end of the table was reached

Type: Numeric

table-id
is the identifier that was assigned when the table was opened. If table-id is invalid, the program halts.

Type: Numeric

row-number
is the number of the row to read.

Type: Numeric

options
is one or both of the following options, separated by blanks:

'ABS'
specifies that the value of row-number is absolute; that is, deleted rows are counted.

'NOSET'
prevents the automatic passing of SAS table column values to SCL variables even if the SET routine has been called.

Type: Character


Details

If SET has previously been called, the values for any table columns that are also window variables or SCL variables for the application are automatically passed from the TDV to the SCL Data Vector (SDV) with FETCHOBS. You can use NOSET in the FETCHOBS function to temporarily override this behavior so that fetched values are not automatically copied to the SDV. FETCHOBS treats the row value as a relative row number unless the ABS option is specified.

The row value may or may not coincide with the physical row number on disk. For example, the function skips rows that have been marked for deletion. When a WHERE clause is active, the function counts only rows that meet the WHERE condition. If row-number is less than 0, the function returns an error condition. If row-number is greater than the number of rows in the SAS table, an 'End of file' warning is returned.


Example

Fetch the tenth row from the SAS table MYDATA. If the end of the table is reached, a message to that effect is displayed on the message line. If an error occurs, the SYSMSG function retrieves the error message and displays it on the message line.

rc=fetchobs(mydata,10);
if (rc=-1) then
  _msg_='End of table has been reached.';
if (rc ne 0) then _msg_=sysmsg();

See Also

APPEND

FETCH

GETVARC and GETVARN

LOCATEC and LOCATEN

PUTVARC and PUTVARN

SET

UPDATE


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.