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.
| Parameter | Description |
|---|---|
| casout | Specifies the properties of the output table. |
| distributeRows | When 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. |
| table | Specifies the input table to be copied. This is a required parameter. |
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.
| 1 | DATA casuser.source_data; |
| 2 | DO i = 1 to 100; |
| 3 | x = rand('UNIFORM'); |
| 4 | y = rand('NORMAL'); |
| 5 | OUTPUT; |
| 6 | END; |
| 7 | RUN; |
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.
| 1 | |
| 2 | PROC CAS; |
| 3 | TABLE.copyTable / TABLE={name='source_data', caslib='casuser'}, casout={name='copy_data', caslib='casuser', replace=true}; |
| 4 | |
| 5 | RUN; |
| 6 |
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.
| 1 | |
| 2 | PROC CAS; |
| 3 | TABLE.copyTable / TABLE={name='source_data', caslib='casuser'}, casout={name='promoted_copy', caslib='casuser', replace=true, promote=true, indexVars={'i'}}; |
| 4 | |
| 5 | RUN; |
| 6 |
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).
| 1 | |
| 2 | PROC CAS; |
| 3 | TABLE.copyTable / TABLE={name='source_data', caslib='casuser', vars={'i', 'x'}, where='i <= 50'}, casout={name='subset_copy', caslib='casuser', replace=true}; |
| 4 | |
| 5 | RUN; |
| 6 |
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 ...
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...
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...