table

fetch

Description

Fetches rows from a table or view. This action allows you to retrieve data from a CAS table to the client for display or further processing. It supports pagination (using 'from' and 'to' parameters), sorting, variable selection, and applying formats.

Settings
ParameterDescription
tableSpecifies the input table name, caslib, and other common parameters (like WHERE clauses or computed variables).
fetchVarsSpecifies the list of variables (columns) to retrieve. If not specified, all variables are returned.
fromSpecifies the starting row number (ordinal position) to return. Defaults to 1.
toSpecifies the ending row number (ordinal position) to return. Defaults to 20.
maxRowsSpecifies the maximum number of rows to return. Defaults to 1000.
sortBySpecifies the variables to sort the results by, including the sort order (ASCENDING or DESCENDING).
formatWhen set to TRUE, formats are applied to the fetched values. Default is FALSE.
indexWhen set to TRUE, adds a column named 'Index' to the results identifying the row number. Default is TRUE.
sasTypesWhen set to TRUE, converts data types to standard SAS types (fixed-width character and double). Default is TRUE.
Data Preparation View data prep sheet
Data Creation

Load the SASHELP.CARS dataset into the CASUSER caslib for demonstration.

Copied!
1 
2PROC CAS;
3dataStep.runCode / code="
4data casuser.cars;
5set sashelp.cars;
6 
7run;
8";
9 
10RUN;
11 

Examples

Fetch the first 5 rows of the 'cars' table.

SAS® / CAS Code Code awaiting community validation
Copied!
1 
2PROC CAS;
3TABLE.fetch / TABLE="cars" from=1 to=5;
4 
5RUN;
6 
Result :
Result table displaying the first 5 rows of the cars table with all columns.

Fetch specific columns (Make, Model, MSRP) for cars originating in Europe, sorted by MSRP in descending order, returning rows 1 through 10.

SAS® / CAS Code Code awaiting community validation
Copied!
1 
2PROC CAS;
3TABLE.fetch / TABLE={name="cars", where="Origin='Europe'"} fetchVars={"Make", "Model", "MSRP"} sortBy={{name="MSRP", order="DESCENDING"}} from=1 to=10;
4 
5RUN;
6 
Result :
Result table showing Make, Model, and MSRP for the 10 most expensive European cars.

FAQ

What is the primary purpose of the fetch action?
How can I specify which columns to retrieve from the table?
How can I filter the rows that are returned?
Is it possible to sort the results returned by the fetch action?
How can I limit the number of rows returned?
What does the "sasTypes" parameter do?
How can I include a column that identifies each row in the results?