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.
| Parameter | Description |
|---|---|
| table | Specifies the input table name, caslib, and other common parameters (like WHERE clauses or computed variables). |
| fetchVars | Specifies the list of variables (columns) to retrieve. If not specified, all variables are returned. |
| from | Specifies the starting row number (ordinal position) to return. Defaults to 1. |
| to | Specifies the ending row number (ordinal position) to return. Defaults to 20. |
| maxRows | Specifies the maximum number of rows to return. Defaults to 1000. |
| sortBy | Specifies the variables to sort the results by, including the sort order (ASCENDING or DESCENDING). |
| format | When set to TRUE, formats are applied to the fetched values. Default is FALSE. |
| index | When set to TRUE, adds a column named 'Index' to the results identifying the row number. Default is TRUE. |
| sasTypes | When set to TRUE, converts data types to standard SAS types (fixed-width character and double). Default is TRUE. |
Load the SASHELP.CARS dataset into the CASUSER caslib for demonstration.
| 1 | |
| 2 | PROC CAS; |
| 3 | dataStep.runCode / code=" |
| 4 | data casuser.cars; |
| 5 | set sashelp.cars; |
| 6 | |
| 7 | run; |
| 8 | "; |
| 9 | |
| 10 | RUN; |
| 11 |
Fetch the first 5 rows of the 'cars' table.
| 1 | |
| 2 | PROC CAS; |
| 3 | TABLE.fetch / TABLE="cars" from=1 to=5; |
| 4 | |
| 5 | RUN; |
| 6 |
Fetch specific columns (Make, Model, MSRP) for cars originating in Europe, sorted by MSRP in descending order, returning rows 1 through 10.
| 1 | |
| 2 | PROC CAS; |
| 3 | TABLE.fetch / TABLE={name="cars", where="Origin='Europe'"} fetchVars={"Make", "Model", "MSRP"} sortBy={{name="MSRP", order="DESCENDING"}} from=1 to=10; |
| 4 | |
| 5 | RUN; |
| 6 |