Published on :

Rename a CAS table

This code is also available in: Deutsch Español Français
Awaiting validation
The script begins by establishing a CAS library (CASLIB) pointing to 'casuser'. It then configures the 'USER' option to direct the creation of single-level tables to this CASLIB. A demonstration table named 'baseball' is created in CAS from the 'sashelp.baseball' table. Finally, the script uses PROC CAS and the 'table.alterTable' action to rename the 'baseball' table to 'baseball' followed by a date (extracted from a macro variable) in the 'casuser' CASLIB.
Data Analysis

Type : SASHELP


The data used for creating the CAS table 'baseball' comes from the standard SASHELP table 'sashelp.baseball'.

1 Code Block
DATA STEP Data
Explanation :
This block initializes a CAS library named 'CASWORK' linked to the 'casuser' CASLIB. It also sets 'CASWORK' as the default library for single-level table names. A CAS table 'baseball' is then created in this CASLIB from 'sashelp.baseball'. A macro variable 'mydate' is defined, and the default CASLIB for CAS actions is set to 'casuser'.
Copied!
1LIBNAME CASWORK cas caslib=casuser;
2options USER = CASWORK;
3 
4%put &_sessref_;
5 
6DATA CASWORK.baseball;
7 SET sashelp.baseball;
8RUN;
9 
10%let mydate=20Apr2020;
11%put &mydate;
12options caslib="casuser";
2 Code Block
PROC CAS
Explanation :
This block uses the CAS procedure (PROC CAS) to execute the 'table.alterTable' action. This action is used to rename the 'baseball' table located in the 'casuser' CASLIB to 'baseball20Apr2020', using the value of the macro variable 'mydate'.
Copied!
1PROC CAS;
2 TABLE.alterTable /
3 caslib="casuser"
4 name="baseball"
5 rename="baseball&mydate";
6QUIT;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
Copyright Info : Copyright © 2021, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. SPDX-License-Identifier: Apache-2.0