Published on :
ETL SASHELP

Appending two CAS tables

This code is also available in: Deutsch Español Français
Awaiting validation
The script initializes a CAS session, then creates two CAS tables named CARS and CARS2 in the CASUSER library, both based on the SASHELP.CARS dataset. It then uses the deepLearn.dlJoin action of PROC CAS with 'joinType = "APPEND"' to copy all rows from CASUSER.CARS2 and append them to CASUSER.CARS. The destination table (CARS) is replaced if it already exists. A message is displayed in the CAS log to confirm the operation.
Data Analysis

Type : SASHELP


The source data for the initial creation of the CASUSER.CARS and CASUSER.CARS2 tables comes from the built-in SASHELP.CARS dataset.

1 Code Block
CAS Session Setup
Explanation :
Initializes a CAS session if not already done and assigns all CAS libraries. The macro variable &_sessref_ displays the active CAS session ID in the log.
Copied!
1cas;
2caslib _all_ assign;
3%put &_sessref_;
2 Code Block
DATA STEP Data
Explanation :
This DATA STEP creates two CAS tables, 'CARS' and 'CARS2', in the 'CASUSER' library. Both are initialized with data from the 'sashelp.cars' example dataset. This is a preparation step for the append operation.
Copied!
1 
2DATA CASUSER.CARS CASUSER.CARS2;
3SET sashelp.cars;
4RUN;
5 
3 Code Block
PROC CAS / deepLearn.dlJoin
Explanation :
This block uses PROC CAS to execute the 'deepLearn.dlJoin' action. The action is configured to perform an append ('joinType = "APPEND"') of the 'CARS2' table (via 'annotatedTable' and 'table') to the 'CARS' table. 'id = "_id_"' specifies an internal identifier column. The result is written to 'CASUSER.CARS', with the 'replace=TRUE' option to replace the existing table if it has the same name. A 'print' statement adds a message to the CAS session log.
Copied!
1PROC CAS;
2DEEPLEARN.dlJoin /
3 annotatedTable = {name = "CARS2", caslib="CASUSER"}
4 TABLE = {name = "CARS2", caslib="CASUSER"}
5 id = "_id_"
6 joinType = "APPEND"
7 casout = {name = "CARS", caslib="CASUSER", replace=TRUE}
8 ;
9 PRINT "Appending CASUSER.CARS2 to CASUSER.CARS";
10RUN;
11QUIT;
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