table

loadTable

Description

Loads a table from a caslib's data source into memory on the CAS server. This action is fundamental for making external data available for analysis in CAS. It supports various file types like CSV, SASHDAT, Parquet, and Excel, and allows for customization through import options.

proc cas; table.loadTable / caslib="string" path="string" casOut={name="string", caslib="string", promote=boolean, replace=boolean} importOptions={fileType="string", ...} dataSourceOptions={...}; run;
Settings
ParameterDescription
attrTableSpecifies the name of an existing extended attributes table to use.
caslibSpecifies the caslib for the data source to load the file from. If not specified, the active caslib is used.
casOutSpecifies the properties of the output in-memory table, such as its name, caslib, and whether to replace an existing table.
dataSourceOptionsProvides options for data sources like databases (e.g., Oracle, Teradata) or Hadoop. For file-based caslibs like PATH, this is not typically used.
importOptionsSpecifies the settings for reading the data, which depend on the file type. For example, for a CSV, you can specify the delimiter.
loadAttrsWhen set to True, automatically loads attributes from a corresponding .ATTRS.sashdat file.
maximumRecordsSpecifies the maximum number of records to load from the source file.
pathSpecifies the file name (or path) within the caslib's data source to load.
promoteWhen set to True, the loaded table is made available to all sessions (global scope), not just the current session.
readAheadWhen set to True, loads the table into memory immediately, rather than waiting for it to be first used.
varsAllows for modification of variable properties like format, label, and length during the load process.
whereSpecifies an expression for subsetting the data as it is loaded from the source file.
Data Preparation View data prep sheet
Create a Sample CSV File

This SAS code snippet creates a simple CSV file named 'cars.csv' in the '/cas/data/' directory, which is accessible by the CAS server. This file will be used as the source for the loadTable action in the examples.

Copied!
1DATA _null_;
2 file '/cas/data/cars.csv' dsd dlm=',';
3 put 'Make,Model,Type,EngineSize,Cylinders,Horsepower,MPG_City,MPG_Highway,Weight,Wheelbase,Length';
4 put 'Acura,MDX,SUV,3.5,6,265,17,23,4451,106,189';
5 put 'Audi,A4 1.8T 4dr,Sedan,1.8,4,170,22,31,3252,104,179';
6 put 'BMW,325i 4dr,Sedan,2.5,6,184,20,30,3219,107,176';
7RUN;

Examples

This example loads the 'cars.csv' file from the 'CASUSER' caslib into an in-memory table named 'CARS_TABLE'. The table will be local to the current session.

SAS® / CAS Code Code awaiting community validation
Copied!
1 
2PROC CAS;
3TABLE.loadTable / caslib='CASUSER' path='cars.csv' casOut={name='CARS_TABLE'};
4 
5RUN;
6 
Result :
The 'CARS_TABLE' is successfully loaded into memory in the 'CASUSER' caslib. A confirmation message listing the output table name and caslib is returned.

This example loads the 'cars.csv' file but also uses the `importOptions` parameter to specify the file type explicitly. The `casOut` parameter specifies a new table name 'CARS_GLOBAL', includes a descriptive label, and uses `promote=TRUE` to make the table accessible to all sessions.

SAS® / CAS Code Code awaiting community validation
Copied!
1 
2PROC CAS;
3TABLE.loadTable / caslib='CASUSER' path='cars.csv' casOut={name='CARS_GLOBAL', label='Global Cars
4Data', promote=TRUE} importOptions={fileType='CSV'};
5 
6RUN;
7 
Result :
The table 'CARS_GLOBAL' is loaded and made available with global scope. Subsequent sessions can access this table without needing to load it again. The action result will indicate the creation of the global-scoped table.

This example loads a SASHDAT file named 'mydata.sashdat' from the 'Public' caslib. The resulting in-memory table is named 'PROMOTED_TABLE' and is promoted to global scope for use in other sessions.

SAS® / CAS Code Code awaiting community validation
Copied!
1 
2PROC CAS;
3TABLE.loadTable / caslib='Public' path='mydata.sashdat' casOut={name='PROMOTED_TABLE', promote=TRUE};
4 
5RUN;
6 
Result :
A global in-memory table named 'PROMOTED_TABLE' is created from the 'mydata.sashdat' file. A confirmation message showing the caslib and table name is displayed.

FAQ

What is the primary purpose of the loadTable action?
What is the 'path' parameter used for in the loadTable action?
How can I specify the output table for the loaded data?
Is it possible to overwrite an existing in-memory table when using loadTable?
What does the 'promote' parameter do?
How can I filter the data being loaded from the source file?
What is the function of the 'importOptions' parameter?