SAS Made Simple: Into the Multiv(iya)erse - Understanding Scope and Loading Tables in SAS Viya

SAS Viya is a comprehensive data analytics platform, which is particularly useful due to the speed improvements, compared to older versions of SAS, offered by the parallel processing of the SAS Cloud Analytics Service (CAS) within SAS Viya.

However, it can be confusing to actually understand which version of a dataset you are using, with multiple versions of the same table existing simultaneously in subtly different environments, so in this blog I will try to explain these differences.

I will use an example where you are taking a table from a database, need to modify it and then use that table permanently, for example maybe in a SAS Visual Analytics dashboard. The majority of the time this is using SAS’s casutil procedure There are 4 steps outlined in the diagram below, which are explained throughout the rest of the blog.

Loading tables

A lot of the time when using SAS Viya, you will be connected to another data source via a data connector, which will mean you are accessing that database via a caslib. However, it is not possible to directly interact with the data in the database, you first need to load the data into memory in the Cloud Analytics Service (CAS). 

This can be done programmatically in a few ways; the following code is an example using proc casutil, and is represented by step 1 in the diagram.

  proc casutil session=YOURSESS incaslib="yourcaslib" outcaslib="yourcaslib";
  	load casdata="yourtable" casout="yourtable" replace;
  quit;

 This now means there are two versions of your table of choice, the one inside the database and then the one loaded into CAS. 

Promoting tables from local to global scope

Once you have loaded your table into CAS, it will be “globally” available. That means all users with permission are able to access that table and use it.

However, when you are accessing data in SAS Studio, you do not directly modify the global-scope tables, instead, any changes you make to a table will only affect a “session-scope” version of the table. All the work done inside a SAS studio session will only be staying within the session, unless you explicitly write code to change a global table.

So in this example, you have now modified your table inside SAS studio, but now there are 3 versions of your table possible to access! This is the table in the database, the global-scope table, and the local-scope table. As mentioned earlier, you may want the changes you have made to this table to also be available outside of your SAS Studio session, for this you need to promote your session-scope table to global-scope table.

However, there isn’t a “replace” option when promoting a table, so in your SAS Studio session you will need to drop the global-scope table, before promoting your modified session-scope table to be available globally. It is even further complicated that you have to drop both the session-scope and global-scope tables at the same time, so you must create a temporary table before promoting.

These three steps are demonstrated in the code below, and represented by steps 2 and 3 on the diagram

/* Create a temporary version of your table*/
data yourcaslib.tmp_table;
set yourcaslib.yourtable;
run;


/* Drop existing versions of table, you have to drop session table before it allows you to drop global table*/
proc casutil session=YOURSESS incaslib="yourcaslib" outcaslib="yourcaslib";
droptable casdata="yourtable"
droptable casdata="yourtable";
quit;


/* Promote your table to global-scope table
proc casutil session=YOURSESS incaslib="yourcaslib" outcaslib="yourcaslib";
save casdata="tmp_table" casout="yourtable" replace; 
quit;

Saving your tables

Finally, it may be that you want your modified table to be available even if CAS is wiped or restated. This is possible by “saving” the table. This will vary depending on how your caslib and Viya instance is set up, but often files can be saved permanently in a caslib as “.sashdat” files.

This is demonstrated in the following code, and by step 4 in the diagram:

proc casutil session=YOURSESS incaslib="yourcaslib" outcaslib="yourcaslib";
save casdata="yourtable" casout="yourtable" replace; 
quit;

At this point, it is possible there are actually four versions of your table, the original table in the database, the global-scope table, the session-scope table, and the permanent sashdat file.

Hopefully at this point you understand a bit more about the differences in tables in the multiverse of SAS Viya. If you want to know more about the worlds of SAS Viya, then keep an eye on our blog page for even more to come.


For even more information on SAS Viya come check us out at the SAS Innovate conference in London on June 13th 2024, we look forward to seeing you there.

Previous
Previous

SAS Made Simple: Using CAS’ Multi-Node Processing to Improve Data Loading

Next
Next

Tech Talent Charter