SAS Communities Library

We’re smarter together. Learn from this collection of community knowledge and add your expertise.
BookmarkSubscribeRSS Feed

An alternative approach to check the scope of CAS tables

Started ‎12-02-2021 by
Modified ‎12-02-2021 by
Views 4,154

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-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

SAS AI and Machine Learning Courses

The rapid growth of AI technologies is driving an AI skills gap and demand for AI talent. Ready to grow your AI literacy? SAS offers free ways to get started for beginners, business leaders, and analytics professionals of all skill levels. Your future self will thank you.

Get started

Article Tags