table

alterTable

Description

The alterTable action allows for modifying the metadata and properties of an in-memory CAS table. This includes renaming the table, changing its label, modifying column properties such as names, labels, and formats, as well as dropping columns or reordering them. It is a versatile tool for managing table structures directly on the CAS server without needing to recreate tables.

table.alterTable { caslib="string", columnOrder={"variable-name-1", "variable-name-2", ...}, columns={{ binaryType="IMAGE" | "SOUND" | "UNKNOWN" | "VIDEO", drop=TRUE | FALSE, format="string", label="string", name="variable-name", newType="VARBINARY" | "VARCHAR", rename="string" }, {...}}, drop={"variable-name-1", "variable-name-2", ...}, keep={"variable-name-1", "variable-name-2", ...}, label="string", lifetime=64-bit-integer, name="table-name", rename="string", tableRedistUpPolicy="DEFER" | "NOREDIST" | "REBALANCE" };
Settings
ParameterDescription
caslibSpecifies the caslib for the input table. By default, the active caslib is used.
columnOrderSpecifies the order of columns in the table's metadata.
columnsSpecifies a list of dictionaries, each defining alterations for a specific column (e.g., renaming, dropping, changing format/label).
dropSpecifies a list of column names to be dropped from the table.
keepSpecifies a list of column names to be kept in the table; all other columns are dropped.
labelAssigns a new label to the table.
lifetimeSpecifies the number of seconds to keep the table in memory after its last access. After this period, the table is dropped.
nameSpecifies the name of the table to be altered.
renameSpecifies a new name for the table.
tableRedistUpPolicySpecifies the table redistribution policy when the number of worker pods increases on a running CAS server. Can be 'DEFER', 'NOREDIST', or 'REBALANCE'.
Data Preparation View data prep sheet
Data Creation

This code creates a sample table 'CARS_DATA' in the 'casuser' caslib, which will be used in the following examples. The table contains information about different car models.

Copied!
1DATA casuser.CARS_DATA;
2 LENGTH Make $ 15 Model $ 20 Type $ 10;
3 INFILE DATALINES delimiter=',';
4 INPUT Make $ Model $ Type $ MSRP Horsepower;
5 DATALINES;
6Toyota,Camry,Sedan,24000,203
7Ford,Mustang,Coupe,27000,310
8Honda,CR-V,SUV,25000,190
9Chevrolet,Silverado,Truck,30000,355
10Tesla,Model 3,Sedan,40000,283
11;
12RUN;

Examples

This example renames the 'CARS_DATA' table to 'AUTOMOBILES'.

SAS® / CAS Code Code awaiting community validation
Copied!
1 
2PROC CAS;
3TABLE.alterTable / caslib='casuser' name='CARS_DATA' rename='AUTOMOBILES';
4 
5RUN;
6 
Result :
The table 'CARS_DATA' is renamed to 'AUTOMOBILES' within the 'casuser' caslib.

This example adds the label 'Car Information' to the 'AUTOMOBILES' table.

SAS® / CAS Code Code awaiting community validation
Copied!
1 
2PROC CAS;
3TABLE.alterTable / caslib='casuser' name='AUTOMOBILES' label='Car Information';
4 
5RUN;
6 
Result :
The table 'AUTOMOBILES' will now have the specified label.

This example drops the 'MSRP' column from the 'AUTOMOBILES' table.

SAS® / CAS Code Code awaiting community validation
Copied!
1 
2PROC CAS;
3TABLE.alterTable / caslib='casuser' name='AUTOMOBILES' drop={'MSRP'};
4 
5RUN;
6 
Result :
The 'MSRP' column is removed from the 'AUTOMOBILES' table.

This example demonstrates altering multiple columns at once. It renames 'Horsepower' to 'HP', adds a label to 'HP', and applies a currency format to the 'MSRP' column (assuming it wasn't dropped).

SAS® / CAS Code Code awaiting community validation
Copied!
1 
2PROC CAS;
3TABLE.alterTable / caslib='casuser' name='AUTOMOBILES' columns={{name='Horsepower', rename='HP', label='Engine Horsepower'}, {name='MSRP', FORMAT='DOLLAR8.'}};
4 
5RUN;
6 
Result :
The 'Horsepower' column is renamed to 'HP' with a new label, and the 'MSRP' column is formatted as currency.

This example drops the 'Type' and 'MSRP' columns and then specifies a new order for the remaining columns in the table metadata.

SAS® / CAS Code Code awaiting community validation
Copied!
1 
2PROC CAS;
3TABLE.alterTable / caslib='casuser' name='AUTOMOBILES' drop={'Type', 'MSRP'} columnOrder={'Model', 'Make', 'HP'};
4 
5RUN;
6 
Result :
The table will only contain 'Model', 'Make', and 'HP' columns, in that specific order.

This example sets the 'AUTOMOBILES' table to be automatically dropped from memory if it is not accessed for 600 seconds (10 minutes).

SAS® / CAS Code Code awaiting community validation
Copied!
1 
2PROC CAS;
3TABLE.alterTable / caslib='casuser' name='AUTOMOBILES' lifetime=600;
4 
5RUN;
6 
Result :
The table's lifetime is updated. It will be unloaded from memory after 10 minutes of inactivity.

FAQ

What is the primary purpose of the `alterTable` action?
How can I rename a table using this action?
What is the difference between the top-level `drop` parameter and the `drop` option within the `columns` parameter?
How do I change the format and label of a specific column?
Can I reorder the columns in my table?
What does the `lifetime` parameter control?
How can I keep only a specific set of columns and remove all others?
What is the purpose of the `tableRedistUpPolicy` parameter?

Associated Scenarios

Use Case
Marketing Campaign Data Refinement

A marketing team has just received a new list of customer leads. The data is structurally sound but uses inconsistent and non-standard column names and formats. The goal is to c...

Use Case
Data Governance and PII Masking for Financial Reporting

A financial analyst needs to create a summary report on customer transactions. The source table contains sensitive Personally Identifiable Information (PII) and other irrelevant...

Use Case
Table Lifecycle and Performance Management for IoT Data

An administrator is managing a CAS environment that processes large volumes of IoT sensor data. A daily raw table needs to be processed, its columns reordered for query efficien...