Published on :
Administration CREATION_INTERNE

Add a File System Path Caslib

This code is also available in: Deutsch Español Français
Awaiting validation
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