PROC CASUTIL has a variety of capabilities. However, most of us likely use it to simply load data into CAS and possibly replace or promote a table to global scope. The CASUTIL procedure can load data sets from SAS libraries and files from multiple data sources associated with a CASLIB. However, SAS Data sets and external files do not have to be associated with a CASLIB. PROC CASUTIL can use a libname engine (via the LOAD DATA statement) or an external file or fileref (via the LOAD FILE statement). No input CASLIB is required for either of these approaches. PROC CASUTIL can also save CAS tables to the data source associated with a CASLIB, provide information on CAS tables and data source files, and drop CAS tables and delete files from the data source associated with a CASLIB.
Beginning with SAS Viya 3.5, several new parameters and options are available in the CASUTIL procedure. Code examples are provided to illustrate some of these new capabilities.
/* LOAD data to CAS then create INDEX */
proc casutil sessref=mysess;
load casdata="cars.sas7bdat" outcaslib="casuser" casout="cars" replace
importoptions=(filetype="basesas" dtm="auto" debug="dmsglvli");
quit;
proc casutil sessref=mysess;
index casdata="cars" incaslib="casuser" outcaslib="casuser" casout="cars_index" replace
indexvars={"make", "origin"};
quit;
OR
/* Create INDEX during LOAD to CAS */
proc casutil sessref=mysess;
load casdata="cars.sas7bdat" outcaslib="casuser" casout="cars" replace
importoptions=(filetype="basesas" dtm="auto" debug="dmsglvli");
index casdata="cars" incaslib="casuser" outcaslib="casuser" casout="cars_index" replace
indexvars={"make", "origin"};
quit;
In either case, the log will display the following message:
NOTE: The Cloud Analytic Services server processed the request in 0.064576 seconds.
NOTE: Indexes were successfully added to the table "cars_index" in the "casuser" caslib.
Output from a PROC CONTENTS will show the indexes that have been applied.
NOTE: Only one of the DROP, KEEP, or COLUMNORDER parameters can be used at one time.
/* LOAD data to CAS then ALTER table */
proc casutil sessref=mysess;
load casdata="cars.sas7bdat" outcaslib="casuser" casout="cars" replace
importoptions=(filetype="basesas" dtm="auto" debug="dmsglvli");
quit;
proc casutil sessref=mysess;
altertable casdata="cars" incaslib="casuser" label="Altered CARS Table"
rename="cars_altered"
/* keep={"make", "model", "type", "origin"} */
columnorder={"origin", "make", "model", "type"};
quit;
OR
/* ALTER table during LOAD to CAS */
proc casutil sessref=mysess;
load casdata="cars.sas7bdat" outcaslib="casuser" casout="cars" replace
importoptions=(filetype="basesas" dtm="auto" debug="dmsglvli");
altertable casdata="cars" incaslib="casuser" label="Altered CARS Table"
rename="cars_altered"
/* keep={"make", "model", "type", "origin"} */
columnorder={"origin", "make", "model", "type"};
quit;
In either case, the log will display the following message:
NOTE: The Cloud Analytic Services server processed the request in 0.027774 seconds.
NOTE: Table "cars" was successfully renamed in the "casuser" caslib to table "cars_altered".
NOTE: Label for table "cars" in the "casuser" caslib was successfully updated to "Altered CARS Table".
NOTE: Column information for table "cars" in the "casuser" caslib was successfully updated.
/* LOAD data to CAS then PARTITION */
proc casutil sessref=mysess;
load casdata="cars.sas7bdat" outcaslib="casuser" casout="cars" replace
importoptions=(filetype="basesas" dtm="auto" debug="dmsglvli");
quit;
proc casutil sessref=mysess;
partition casdata="cars" incaslib="casuser" outcaslib="casuser" casout="cars_part" replace
partitionby=(make origin);
quit;
OR
/* PARTITION data during LOAD to CAS */
proc casutil sessref=mysess;
load casdata="cars.sas7bdat" outcaslib="casuser" casout="cars" replace
importoptions=(filetype="basesas" dtm="auto" debug="dmsglvli");
partition casdata="cars" incaslib="casuser" outcaslib="casuser" casout="cars_part" replace
partitionby=(make origin);
quit;
In either case, the log will display the following message:
NOTE: The Cloud Analytic Services server processed the request in 0.07634 seconds.
NOTE: The table "cars_part" in the "casuser" caslib was successfully partitioned.
/* LOAD data to CAS then UPDATE */
proc casutil sessref=mysess;
load casdata="cars.sas7bdat" outcaslib="casuser" casout="cars" replace
importoptions=(filetype="basesas" dtm="auto" debug="dmsglvli");
quit;
proc casutil sessref=mysess;
update casdata="cars" incaslib="casuser"
set={{var="cylinders", value="12"}}
where="invoice > 30000";
quit;
OR
/* UPDATE data during LOAD to CAS */
proc casutil sessref=mysess;
load casdata="cars.sas7bdat" outcaslib="casuser" casout="cars" replace
importoptions=(filetype="basesas" dtm="auto" debug="dmsglvli");
update casdata="cars" incaslib="casuser"
set={{var="cylinders", value="12"}}
where="invoice > 30000";
quit;
Partial output of the updated table.
There are many more enhancements to existing procedures and action sets in SAS Viya 3.5. Please consult the documentation on www.sas.com once SAS Viya 3.5 is available in November 2019.
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning and boost your career prospects.