SAS & CAS: Many Hands Make Light Work

What is CAS?

SAS Cloud Analytic Services (CAS) is a server that provides a cloud-based, run-time environment for data management and analytics with SAS. It allows data management and analytics to take place on either a single machine or as a distributed server across multiple machines. To use the power of CAS, SAS Tables must be stored in CASLIBS, similar to how you would use a SASLIB. These tables are then loaded into CAS memory for faster processing.

To start a CAS session and assign all CASLIBs by default, you can run the following command:

cas;

caslib _all_ assign;

You can assign tables to a CASLIB as you would use any other SASLIB e.g data step, proc sql. 

Tables stored in memory are denoted by a small lightning icon. Think “Loaded” and Lightning Fast. Tables saved as data are denoted by a small snowflake icon. Think “Saved”, sashdata and Snowflake


What is Scoping?

Scoping is an important part of CAS that will really confuse you if you do not pay attention. You have two different types of scope: session level and global level scope.

Session level scope means it is only accessible to your CAS session. Session level tables take precedence over Global scope tables. So if you have a Session level table and a Global table both sharing the same name then you will see the Session level table rather than the Global. If you delete the Session level table then the Global level table will now appear. 

Global level scope means that all CAS sessions can access the tables in the caslib and not just yours. This means you can share your data with other users, however they can also modify this data. 

With the correct permissions, you can Promote a table to go from Session to Global scope.If you do this then the table must not be named the same as a pre-existing Global table. This of course makes it difficult to renew Global tables easily. To do this you can either drop the Global table before promoting your Session level table (Appendix 1) or you can upload your Session level table under a different name and then alter both table names (Appendix 2).

Appendix 1 - Replace a Global table with a Session table with the same name.

proc cas util incaslib=”CASLIB” outcaslib=“CASLIB”;

/* save your sastable to a .sashdat file */

save casdata=“TABLE” casout= “TABLE” replace; 

/* drop both the session and the global table */

droptable incaslib= “CASLIB” casdata= “TABLE” QUIET;

droptable incaslib= “CASLIB” casdata= “TABLE” QUIET;

/* load and promote your previously saved table */

load casdata= “TABLE.sashdat” casout= “TABLE.sashdat” promote;

quit;


Appendix 2 - Replace a Global table with a Session table with the same name.

proc cas util incaslib=”CASLIB” outcaslib=“CASLIB”;

/* to save a sastable to a .sashdat file */

save casdata=“TABLE” casout= “TABLE” replace; 

/* drop the new table in cas it exists */

droptable incaslib= “CASLIB” casdata= “TABLE_NEW” QUIET;

/* promote your table with the new table name */

load casdata= “TABLE.sashdat” casout= “TABLE_NEW” promote;

/* tactically rename the files  */

altertable casdata= “TABLE” rename= “TABLE_OLD”;

altertable casdata= “TABLE_NEW” rename= “TABLE_OLD”;

/* drop the table which is no longer needed*/

droptable incaslib= “CASLIB” casdata= “TABLE_OLD” QUIET;

quit;

Previous
Previous

Big Government Data Strategy - No more Chief Data Ostrich!

Next
Next

World Well-Being Week