?>
The addTable action is a fundamental mechanism for transferring data from a client-side process to the CAS server, creating an in-memory table. Unlike actions like loadTable which load data from server-side sources, addTable is specifically used by client libraries (SAS SWAT for Python, R, Lua) to upload data structures (e.g., Pandas DataFrames, R data frames) directly into a CAS table. It provides detailed control over the resulting table's properties, such as column types, lengths, labels, and memory layout.
| Parameter | Description |
|---|---|
| append | Specifies whether to add rows from the table to an existing table. |
| caslib | Specifies the target caslib for the table. |
| columnar | Specifies to create the in-memory table in columnar format. |
| commitRecords | Specifies the number of rows for the server to receive before committing the rows to the table. |
| commitSeconds | Specifies the number of seconds for the server to receive rows before committing the rows to the table. |
| compress | When set to True, compresses the target table. |
| copies | Specifies the number of redundant copies to make for the rows. Larger values provide greater fault tolerance but use more memory. |
| descending | Specifies to reverse the sort order for the specified variables in the orderBy parameter. |
| label | Specifies a descriptive label for the table. |
| maxMBytes | Specifies the maximum amount of physical memory, in megabytes, to allocate for the table. |
| memoryFormat | Specifies the memory format for the output table (DVR, INHERIT, or STANDARD). |
| orderBy | Specifies the variable names to use for ordering rows within partitions. |
| partition | Specifies the variable names to use as partitioning keys. |
| promote | When set to True, the table is added with a global scope, making it accessible to other sessions. |
| recLen | Specifies the length, in bytes, for a row. This is a required parameter. |
| repeat | When set to True, the rows for the table are duplicated on every machine of a distributed server. |
| replace | When set to True, an existing table with the same name is overwritten. |
| table | Specifies the output table name. |
| vars | Specifies the attributes for each variable, such as name, type, length, and format. |
The `addTable` action is used by client-side utilities to upload data. For example, in Python, you would typically create a Pandas DataFrame first. This DataFrame is then uploaded to the CAS server, which internally uses the `addTable` action.
/* This is a conceptual representation. In practice, you'd use a client like Python's SWAT library. */
proc cas;
/* Step 1: Define data on the client (e.g., a Pandas DataFrame in Python) */
/* df = pd.DataFrame({'model': ['Mustang', 'F-150', 'Explorer'], 'msrp': [27000, 35000, 32000]}) */
/* Step 2: Use the client library's upload function, which calls table.addTable */
/* cas_conn.upload_frame(df, casout={'name':'cars', 'caslib':'casuser'}) */
quit;This example demonstrates the typical usage of `addTable` via a client library. A local data structure is created and then uploaded to the CAS server, creating a new in-memory table named 'CARS' in the 'CASUSER' caslib.
| 1 | PROC CAS; |
| 2 | /* In Python, this would be: df = pd.DataFrame({'model': ['Mustang', 'F-150'], 'msrp': [27000, 35000]}); s.upload_frame(df, casout={'name':'cars', 'caslib':'casuser'}); */ |
| 3 | TABLE.addTable / caslib='casuser' TABLE='CARS' vars={{name='model', type='varchar', LENGTH=10},{name='msrp', type='double'}}; |
| 4 | QUIT; |
This example shows a more advanced upload. It specifies column labels and formats. `replace=TRUE` ensures that if a table named 'SALES_DATA' already exists, it will be overwritten. `promote=TRUE` makes the table available to all other CAS sessions, not just the current one.
| 1 | PROC CAS; |
| 2 | /* Python equivalent: s.upload_frame(df, casout={'name':'sales_data', 'caslib':'casuser', 'replace':True, 'promote':True}, var_attr={'product_id':{'label':'Product Identifier'}, 'sale_date':{'format':'DATE9.'}}) */ |
| 3 | TABLE.addTable / |
| 4 | caslib='casuser' |
| 5 | TABLE='SALES_DATA' |
| 6 | replace=TRUE |
| 7 | promote=TRUE |
| 8 | label='Quarterly Sales Figures' |
| 9 | vars={{ |
| 10 | name='product_id', |
| 11 | type='varchar', |
| 12 | LENGTH=15, |
| 13 | label='Product Identifier' |
| 14 | },{ |
| 15 | name='sale_date', |
| 16 | type='double', |
| 17 | FORMAT='DATE9.', |
| 18 | label='Date of Sale' |
| 19 | },{ |
| 20 | name='sale_amount', |
| 21 | type='double', |
| 22 | FORMAT='DOLLAR12.2', |
| 23 | label='Sale Amount' |
| 24 | }}; |
| 25 | QUIT; |
A retail company needs to upload its daily sales transactions into CAS for analysis. The process runs every morning, and the previous day's data must be completely replaced with...
A manufacturing company ingests millions of data points from IoT sensors on its assembly line machines. To enable rapid failure analysis and predictive modeling, the data must b...
A marketing analytics team needs to consolidate customer responses from multiple campaign waves into a single master table. The initial data is loaded, and subsequent data from ...