Data Access SAS VIYA CAS

Beyond the Work Library: Mounting Server Directories in CAS using table.addCaslib

This code is also available in: Deutsch Español Français
Difficulty Level
Beginner
Published on :
Michael

Expert Advice

Michael
Responsable de l'infrastructure Viya.

As an SEO expert and Copywriter, I’ve analyzed your article. The term "File System Path Caslib" is technically accurate but rarely what a user types into a search engine. Users usually search for how to mount directories, SAS Viya data access, or CAS connectivity.

Here are 3 title variations designed to improve your search ranking and click-through rate:

1. The "Power User" Title (SEO Optimized)
Mastering SAS Viya: How to Create Path-Based Caslibs for Persistent Data Access

Why it works: It uses high-value keywords like "SAS Viya," "Path-Based Caslibs," and "Persistent Data Access." It promises a "Mastering" level of knowledge, which attracts professionals looking for best practices in data administration.

2. The Data Engineering Title (The Statistician's Choice)
Beyond the Work Library: Mounting Server Directories in CAS using table.addCaslib

Why it works: Most SAS users are familiar with the WORK library. By positioning this as the next step ("Beyond"), you pique curiosity. It specifically mentions the technical action table.addCaslib, which is a high-intent keyword for developers looking for syntax.

3. The "Productivity" Title (Moderate Clickbait)
Stop Losing Data! The Pro Way to Configure Global and Dynamic Path Caslibs in SAS

Why it works: It uses an emotional hook ("Stop Losing Data!") to address the pain point of non-persistent data in CAS. It highlights "Global" and "Dynamic" configurations, signaling to the reader that this guide covers advanced, real-world scenarios rather than just a basic setup.

Technical Tip (Plain Text)
When using the table.addCaslib action with srctype='path', remember that the specified directory must be physically accessible by every node in your CAS grid (usually via a shared file system like NFS or Lustre); if you specify a local path that exists only on the controller node, the worker nodes will fail to access the data during distributed processing.

Attention : This code requires administrator privileges.
The `table.addCaslib` action is an essential action of the `table` action set in SAS© Cloud Analytic Services (CAS). It allows registering a new caslib, which is a logical name that points to a data source. In the case of a 'path' type caslib, it refers to a directory on the CAS server's file system. Key parameters include `name` for the caslib's name, `description` for a brief explanation, `dataSource` where `srctype` is set to 'path', and `path` for the absolute path to the directory on the server. This action is fundamental for making data persistent and accessible to CAS sessions for distributed analysis and manipulation.
Data Analysis

Type : CREATION_INTERNE


The provided examples use generic file system paths (`/tmp/mydata`, `/project/data`, `/cas/data/dynamic_source`, `/tmp/my_user_data`) which must exist or be created on the CAS server's file system. The advanced example also uses a SASHELP table (`CARS`) for data loading demonstration.

1 Code Block
PROC CAS Data
Explanation :
This example shows the creation of a simple caslib named 'mybasiccaslib' that points to the `/tmp/mydata` directory on the CAS server's file system. It then includes a verification of this caslib's creation.
Copied!
1PROC CAS;
2 SESSION casauto;
3 TABLE.addCaslib /
4 name="mybasiccaslib",
5 description="Caslib de base pour mes données",
6 dataSource={srctype="path"},
7 path="/tmp/mydata";
8RUN;
9 
10/* Vérifier que la caslib a été ajoutée */
11PROC CAS;
12 SESSION casauto;
13 TABLE.caslibinfo / caslib="mybasiccaslib";
14RUN;
2 Code Block
PROC CAS Data
Explanation :
This example creates a caslib named 'global_project_data' that includes common options. The `subdirs=TRUE` option allows the caslib to recognize and access subdirectories of the specified path. The `globals=TRUE` option makes this caslib accessible to all CAS sessions, not just the session of the user who created it.
Copied!
1PROC CAS;
2 SESSION casauto;
3 TABLE.addCaslib /
4 name="global_project_data",
5 description="Données de projet avec sous-répertoires et accès global",
6 dataSource={srctype="path"},
7 path="/project/data",
8 subdirs=TRUE,
9 globals=TRUE;
10RUN;
11 
12/* Vérifier la configuration de la caslib */
13PROC CAS;
14 SESSION casauto;
15 TABLE.caslibinfo / caslib="global_project_data";
16RUN;
3 Code Block
PROC CAS / Commandes Shell Data
Explanation :
This advanced example illustrates the dynamic creation and management of a caslib using SAS macro variables. It starts by creating a directory on the CAS server's file system via a shell command. Then, it adds a caslib (`DynamicCaslib`) that points to this directory, defining it as inactive (`active=FALSE`) initially. The caslib is then activated, and its state is verified. Finally, the example includes cleanup steps to delete the caslib and the created directory, demonstrating a complete lifecycle.
Copied!
1%let myCaslibName = DynamicCaslib;
2%let myCaslibPath = /cas/DATA/dynamic_source;
3 
4/* Assurez-vous que le chemin existe pour l'exemple */
5/* Ceci exécute une commande shell pour créer le répertoire sur le serveur CAS */
6filename _TEMP_CMD_ pipe "mkdir -p &myCaslibPath";
7DATA _null_; INFILE _TEMP_CMD_ ; INPUT; RUN;
8 
9PROC CAS;
10 SESSION casauto;
11 TABLE.addCaslib /
12 name="&myCaslibName",
13 description="Caslib créée dynamiquement via macro-variables",
14 dataSource={srctype="path"},
15 path="&myCaslibPath",
16 active=FALSE; /* La caslib n'est pas activée immédiatement */
17RUN;
18 
19/* Activer la caslib et vérifier */
20PROC CAS;
21 SESSION casauto;
22 TABLE.caslibinfo / caslib="&myCaslibName";
23 TABLE.setCaslib / caslib="&myCaslibName", active=TRUE;
24 TABLE.caslibinfo / caslib="&myCaslibName";
25RUN;
26 
27/* Nettoyage : Supprimer la caslib et le dossier créé */
28PROC CAS;
29 SESSION casauto;
30 TABLE.dropCaslib / caslib="&myCaslibName";
31RUN;
32filename _TEMP_CMD_ pipe "rmdir &myCaslibPath";
33DATA _null_; INFILE _TEMP_CMD_ ; INPUT; RUN;
4 Code Block
PROC CAS / PROC CASUTIL Data
Explanation :
This example demonstrates the creation of a personal caslib (`personal=TRUE`), which is only visible to the CAS session of the user who creates it. The path `/tmp/my_user_data` is used. Then, it uses the `loadcasdata` action to load the `CARS` table from the SASHELP library into this personal caslib, making it available in memory in CAS under the name `cars_in_cas`. The example then lists the tables in this caslib and, finally, deletes the personal caslib. It is important to ensure that the `/tmp/my_user_data` directory exists and is writable by the CAS user.
Copied!
1/* Création d'une caslib personnelle temporaire */
2/* Note: Le chemin doit être accessible et en écriture pour l'utilisateur CAS */
3PROC CAS;
4 SESSION casauto;
5 TABLE.addCaslib /
6 name="my_personal_caslib",
7 description="Caslib personnelle temporaire pour chargement de données",
8 dataSource={srctype="path"},
9 path="/tmp/my_user_data",
10 personal=TRUE,
11 subdirs=TRUE; /* Permettre les sous-répertoires */
12RUN;
13 
14/* Vérifier l'existence et l'activation de la caslib personnelle */
15PROC CAS;
16 SESSION casauto;
17 TABLE.caslibinfo / caslib="my_personal_caslib";
18RUN;
19 
20/* Charger des données SASHELP dans cette caslib personnelle */
21/* Assurez-vous que le répertoire '/tmp/my_user_data' existe et est accessible en écriture */
22PROC CAS;
23 SESSION casauto;
24 loadcasdata /
25 caslib="my_personal_caslib",
26 path="CARS", /* Chargement de la table CARS de SASHELP */
27 casout="cars_in_cas",
28 promote=TRUE; /* Promote la table en mémoire pour être accessible */
29RUN;
30 
31/* Lister les tables dans la caslib personnelle */
32PROC CAS;
33 SESSION casauto;
34 TABLE.tableinfo / caslib="my_personal_caslib";
35RUN;
36 
37/* Supprimer la caslib personnelle */
38PROC CAS;
39 SESSION casauto;
40 TABLE.dropCaslib / caslib="my_personal_caslib";
41RUN;
42 
43/* Nettoyage : Si des fichiers ont été écrits, ils doivent être supprimés manuellement du chemin /tmp/my_user_data */
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
Copyright Info : Copyright © SAS Institute Inc. All Rights Reserved