BookmarkSubscribeRSS Feed

An alternative approach to check the scope of CAS tables

Started ‎12-02-2021 by
Modified ‎12-02-2021 by
Views 3,588

Chances are, your Viya environment contains many caslibs and many tables within these caslibs.  Determining the scope of these tables is extremely important.  This affects your downstream processing.  You don’t want to delete, overwrite, or alter session scope tables by accident.  Conversely, you don’t want to delete promoted tables, especially if they are being accessed by more than one user. 

 

One handy way to determine the scope of a CAS table is via the tableInfo CAS action.  It provides valuable information about a particular table including whether it has been promoted.  The tableInfo action output is written to the results tab in SAS Studio.  An alternative approach is to use the tableExists CAS action.  This action does not produce any output in the results tab.  It merely sends a numeric code to a result table.  Subsequently the result table can be queried to discover the scope of the CAS table.

 

 The following example demonstrates how to leverage this approach.

 

briankinnebrew_0-1638477630499.png

 

First, identify your caslib and CAS table in the two %let statements.  Once the code is executed, a result of 0, 1, or 2 will be written to the result table “r”.  If the table doesn’t exist, a code of 0 will be written to the result table.  A code of 1 will be written for session scoped tables and a code of 2 will be written for globally (promoted) scoped tables.  Using conditional logic coupled with the “exists” dictionary name, a message will be written to the SAS log based on the corresponding code value.  For example, if the CARS dataset is written to the CASUSER caslib as a session scoped table, the following note will be displayed in the SAS log:

 

The CAS table CARS has a session scope.

NOTE: PROCEDURE CAS used (Total process time):

      real time           0.03 seconds

      cpu time            0.03 seconds

 

If the CLASS dataset is written to the CASUSER caslib as a globally scoped table, the following note will be displayed in the SAS log:

 

The CAS table CLASS has a global scope.

NOTE: PROCEDURE CAS used (Total process time):

      real time           0.03 seconds

      cpu time            0.01 seconds

 

Lastly, if you search for a table that is not in CAS, the following message will appear in the SAS log:

 

The CAS table XYZ does not exist.

NOTE: PROCEDURE CAS used (Total process time):

      real time           0.03 seconds

      cpu time            0.01 seconds

 

If it helps you, consider using this technique when checking the scope of your CAS tables.  Happy coding!

Version history
Last update:
‎12-02-2021 03:47 PM
Updated by:
Contributors

SAS INNOVATE 2024

Innovate_SAS_Blue.png

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. 

Register now!

Free course: Data Literacy Essentials

Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning  and boost your career prospects.

Get Started

Article Tags