table

copyTable

Description

The copyTable action allows for the duplication of an in-memory table to another table, potentially in a different caslib. This is useful for creating snapshots, backups, or different versions of a dataset for analysis without altering the original source. The action provides extensive options for the output table, including compression, indexing, labeling, and promotion to a global scope for broader access.

table.copyTable { casout={caslib="string", compress=TRUE|FALSE, indexVars={"variable-name-1", ...}, label="string", lifetime=64-bit-integer, maxMemSize=64-bit-integer, memoryFormat="DVR"|"INHERIT"|"STANDARD", name="table-name", promote=TRUE|FALSE, replace=TRUE|FALSE, replication=integer, tableRedistUpPolicy="DEFER"|"NOREDIST"|"REBALANCE", threadBlockSize=64-bit-integer, timeStamp="string"}, distributeRows=TRUE|FALSE, table={caslib="string", computedOnDemand=TRUE|FALSE, computedVars={{format="string", formattedLength=integer, label="string", name="variable-name", nfd=integer, nfl=integer}, ...}, computedVarsProgram="string", dataSourceOptions={key-1=any-list-or-data-type-1, ...}, groupBy={{format="string", formattedLength=integer, label="string", name="variable-name", nfd=integer, nfl=integer}, ...}, groupByMode="NOSORT"|"REDISTRIBUTE", importOptions={fileType="ANY"|"AUDIO"|"AUTO"|"BASESAS"|"CSV"|"DELIMITED"|"DOCUMENT"|"DTA"|"ESP"|"EXCEL"|"FMT"|"HDAT"|"IMAGE"|"JMP"|"LASR"|"PARQUET"|"SOUND"|"SPSS"|"VIDEO"|"XLS", fileType-specific-parameters}, name="table-name", orderBy={{format="string", formattedLength=integer, label="string", name="variable-name", nfd=integer, nfl=integer}, ...}, singlePass=TRUE|FALSE, vars={{format="string", formattedLength=integer, label="string", name="variable-name", nfd=integer, nfl=integer}, ...}, where="where-expression", whereTable={casLib="string", dataSourceOptions={...}, importOptions={...}, name="table-name", vars={{...}}, where="where-expression"}} };
Settings
ParameterDescription
casoutSpecifies the properties of the output table.
distributeRowsWhen set to True, table rows from the original table are distributed amongst the workers in the copy. By default, rows remain on their original worker.
tableSpecifies the input table to be copied. This is a required parameter.
Data Preparation View data prep sheet
Data Creation: Sample Source Table

This code creates a simple in-memory table named 'source_data' in the 'casuser' caslib. This table will serve as the source for the copyTable examples.

Copied!
1DATA casuser.source_data;
2 DO i = 1 to 100;
3 x = rand('UNIFORM');
4 y = rand('NORMAL');
5 OUTPUT;
6 END;
7RUN;

Examples

This example demonstrates a simple copy of the 'source_data' table to a new table named 'copy_data' within the same 'casuser' caslib. The 'replace' option is used to overwrite the destination table if it already exists.

SAS® / CAS Code Code awaiting community validation
Copied!
1 
2PROC CAS;
3TABLE.copyTable / TABLE={name='source_data', caslib='casuser'}, casout={name='copy_data', caslib='casuser', replace=true};
4 
5RUN;
6 
Result :
The action creates a new table named 'copy_data' in the 'casuser' caslib, which is an exact duplicate of the 'source_data' table.

This example copies the 'source_data' table to a new table named 'promoted_copy'. The 'promote' option makes the table available to all sessions (global scope), and an index is created on the 'i' column to potentially speed up queries.

SAS® / CAS Code Code awaiting community validation
Copied!
1 
2PROC CAS;
3TABLE.copyTable / TABLE={name='source_data', caslib='casuser'}, casout={name='promoted_copy', caslib='casuser', replace=true, promote=true, indexVars={'i'}};
4 
5RUN;
6 
Result :
A new globally-scoped table 'promoted_copy' is created. It contains the same data as 'source_data' and has an index on the 'i' column.

This example copies only a subset of the 'source_data' table. It selects only the 'i' and 'x' columns ('vars' parameter) and filters the rows to include only those where 'i' is less than or equal to 50 ('where' parameter).

SAS® / CAS Code Code awaiting community validation
Copied!
1 
2PROC CAS;
3TABLE.copyTable / TABLE={name='source_data', caslib='casuser', vars={'i', 'x'}, where='i <= 50'}, casout={name='subset_copy', caslib='casuser', replace=true};
4 
5RUN;
6 
Result :
A new table 'subset_copy' is created containing only the columns 'i' and 'x' for the first 50 rows of the original table.

Associated Scenarios

Use Case
Standard: Snapshot for Marketing Analysis with Computed Metrics

The marketing department needs a static snapshot of active high-value customers to run a targeted email campaign. The source table is live and constantly updating. They need to ...

Use Case
Performance: Archiving Massive Sensor Data with Compression and Indexing

A manufacturing plant gathers massive vibration data from sensors. To optimize memory usage and query speed for historical analysis, the engineering team needs to archive raw da...

Use Case
Edge Case: PII Removal and Handling Missing Data

For a regulatory audit, a bank must extract loan data while strictly removing Personally Identifiable Information (PII) like 'SSN'. The process must also handle data quality iss...