This is where the tableInfo action from the table action set comes in.
In this tutorial, we will explore how to use this essential command for data exploration, from its basic syntax to advanced wildcard character management.
The tableInfo action allows you to obtain detailed metadata about one or more tables loaded in memory in a specific caslib.
Key parameters:
caslib: The name of the CAS library where the table is located.
name: The name of the target table.
quiet: A boolean (True/False). If enabled, it suppresses error messages if the table does not exist (very useful for automated scripts).
wildIgnore: Determines whether special characters (% and _) should be treated as wildcards or as literal text.
wildEscape: Defines the escape character to force a literal reading of a wildcard.
Note :
Use Case 1: Basic Usage
Objective: Check the information of a specific table.
In this first example, we will load a small table into memory and request its information. This is the most standard use case: you know the name of the table and its location.
cas;
/* 1. Création d'une table temporaire en mémoire CAS */
DATA casuser.ma_table_basique;
INPUT ID Name $ Value;
DATALINES;
1 Alice 100
2 Bob 150
3 Charlie 120
;
RUN;
/* 2. Afficher les informations de la table */
PROC CAS;
TABLE.tableInfo RESULT=r /
name="ma_table_basique"
caslib="casuser";
PRINT r;
RUN;
1
cas;
2
3
/* 1. Création d'une table temporaire en mémoire CAS */
4
DATA casuser.ma_table_basique;
5
INPUT ID Name $ Value;
6
DATALINES;
7
1 Alice 100
8
2 Bob 150
9
3 Charlie 120
10
;
11
RUN;
12
13
/* 2. Afficher les informations de la table */
14
PROC CAS;
15
TABLE.tableInfo RESULT=r /
16
name="ma_table_basique"
17
caslib="casuser";
18
PRINT r;
19
RUN;
First, we create a table `ma_table_basique` in the personal caslib `casuser`. Then, the `table.tableInfo` action is called. The result (stored in the variable `r`) will contain columns like Name, Rows, Columns, and CreateTime.
Note :
Use Case 2: Handling Non-Existent Tables (Quiet Option)
Objective: Prevent your program from crashing if a table is missing.
cas;
/* Création d'une table de référence */
DATA samples.produits_ventes;
INPUT Annee Produit $ Quantite Prix;
DATALINES;
2023 A 10 100
2023 B 20 50
;
RUN;
PROC CAS;
/* Cas A : Table introuvable avec quiet=TRUE */
TABLE.tableInfo RESULT=r_non_existent /
name="table_introuvable"
quiet=TRUE;
PRINT "Tentative sur table inexistante :";
PRINT r_non_existent;
/* Cas B : Table existante standard */
TABLE.tableInfo RESULT=r_existent /
name="produits_ventes"
caslib="Samples";
PRINT "Tentative sur table existante :";
PRINT r_existent;
RUN;
1
cas;
2
3
/* Création d'une table de référence */
4
DATA samples.produits_ventes;
5
INPUT Annee Produit $ Quantite Prix;
6
DATALINES;
7
2023 A 10100
8
2023 B 2050
9
;
10
RUN;
11
12
PROC CAS;
13
/* Cas A : Table introuvable avec quiet=TRUE */
14
TABLE.tableInfo RESULT=r_non_existent /
15
name="table_introuvable"
16
quiet=TRUE;
17
18
PRINT"Tentative sur table inexistante :";
19
PRINT r_non_existent;
20
21
/* Cas B : Table existante standard */
22
TABLE.tableInfo RESULT=r_existent /
23
name="produits_ventes"
24
caslib="Samples";
25
26
PRINT"Tentative sur table existante :";
27
PRINT r_existent;
28
RUN;
In Case A, we are looking for `table_introuvable`. Thanks to `quiet=TRUE`, the log will not display a blocking red error. The result object will be empty or indicate an 'OK' status but with no table data, which allows your code to continue its execution (for example, to load the missing table).
Note :
Use Case 3: Using Wildcards
Objective: List all tables that follow a certain pattern.
This is a very powerful feature for exploration. For example, to process all sales tables for a given year.
cas;
/* Création de plusieurs tables pour l'exemple */
DATA casuser.donnees_2023_Q1; ID=1; RUN;
DATA casuser.donnees_2023_Q2; ID=2; RUN;
DATA casuser.donnees_2024_Q1; ID=3; RUN;
PROC CAS;
/* Rechercher toutes les tables commençant par "donnees_2023_" */
TABLE.tableInfo RESULT=r_wildcard /
name="donnees_2023_%" /* Le motif recherché */
caslib="casuser"
wildIgnore=FALSE; /* Active l'interprétation du '%' */
PRINT r_wildcard;
RUN;
1
cas;
2
3
/* Création de plusieurs tables pour l'exemple */
4
DATA casuser.donnees_2023_Q1; ID=1; RUN;
5
DATA casuser.donnees_2023_Q2; ID=2; RUN;
6
DATA casuser.donnees_2024_Q1; ID=3; RUN;
7
8
PROC CAS;
9
/* Rechercher toutes les tables commençant par "donnees_2023_" */
10
TABLE.tableInfo RESULT=r_wildcard /
11
name="donnees_2023_%"/* Le motif recherché */
12
caslib="casuser"
13
wildIgnore=FALSE; /* Active l'interprétation du '%' */
14
15
PRINT r_wildcard;
16
RUN;
Here, `wildIgnore=FALSE` is essential. It tells CAS: "Do not treat the % character as a letter, but as a wildcard." The action will therefore return the metadata for `donnees_2023_Q1` and `donnees_2023_Q2`, but will ignore the one from 2024.
Note :
Use Case 4: Escaping Special Characters
Objective: Find a table whose name actually contains a % or a _.
This is a rarer but technical case. If your table is named `resultat_final_%_test`, how do you search for it without the % being seen as a wildcard? You need to use an escape character via `wildEscape`.
cas;
/* Création d'une table avec un nom complexe */
DATA casuser."resultat_final_%_test";
ID=10; Score=95.5;
RUN;
PROC CAS;
TABLE.tableInfo RESULT=r_escape /
name="resultat_final_\%_test" /* Le \ protège le % */
caslib="casuser"
wildIgnore=FALSE /* On garde le mode wildcard actif */
wildEscape="\\"; /* On définit \ comme le protecteur */
PRINT r_escape;
RUN;
1
cas;
2
3
/* Création d'une table avec un nom complexe */
4
DATA casuser."resultat_final_%_test";
5
ID=10; Score=95.5;
6
RUN;
7
8
PROC CAS;
9
TABLE.tableInfo RESULT=r_escape /
10
name="resultat_final_\%_test"/* Le \ protège le % */
11
caslib="casuser"
12
wildIgnore=FALSE /* On garde le mode wildcard actif */
13
wildEscape="\\"; /* On définit \ comme le protecteur */
14
15
PRINT r_escape;
16
RUN;
In this example:
`wildIgnore=FALSE`: The wildcard mode is active (necessary to use `wildEscape`).
Los códigos y ejemplos proporcionados en WeAreCAS.eu son con fines educativos. Es imperativo no copiarlos y pegarlos ciegamente en sus entornos de producción. El mejor enfoque es comprender la lógica antes de aplicarla. Recomendamos encarecidamente probar estos scripts en un entorno de prueba (Sandbox/Dev). WeAreCAS no acepta ninguna responsabilidad por cualquier impacto o pérdida de datos en sus sistemas.
SAS y todos los demás nombres de productos o servicios de SAS Institute Inc. son marcas registradas o marcas comerciales de SAS Institute Inc. en los EE. UU. y otros países. ® indica registro en los EE. UU. WeAreCAS es un sitio comunitario independiente y no está afiliado a SAS Institute Inc.
Este sitio utiliza cookies técnicas y analíticas para mejorar su experiencia.
Saber más.