In SAS Viya, compression isn't a "set it and forget it" feature. Because CAS is a massively parallel processing (MPP) engine, the way you store data directly impacts how it is distributed across your nodes.
Compression vs. Partitioning
Your code demonstrates combining PARTITION= and COMPRESS=. This is an expert-level pattern. By partitioning the data, you reduce the amount of data that needs to be decompressed for specific queries, as CAS only "touches" the partitions required for the analysis.
Examples use generated data (datalines) or the SASHELP library.
1 Code Block
DATA Step Data
Explanation : This example illustrates creating a compressed CAS table from an existing table using a DATA Step. The `compress=yes` option is specified in the output table options, instructing CAS to compress data in memory. A `PROC CASUTIL CONTENTS` is used to verify table properties, including compression status.
Copied!
/* Établit une connexion CAS (à adapter à votre environnement) */
libname mycas cas caslib=casuser;
/* Crée une table non compressée pour l'exemple */
data mycas.ventes_non_compresse;
length produit $20 quantite prix 8;
input produit $ quantite prix;
datalines;
Pomme 10 1.50
Banane 5 0.75
Orange 12 1.20
;
run;
/* Crée une copie compressée de la table 'ventes_non_compresse' */
data mycas.ventes_compresse (compress=yes);
set mycas.ventes_non_compresse;
run;
/* Affiche les propriétés de la table compressée (y compris la compression) */
proc casutil incaslib="casuser" outcaslib="casuser";
contents casdata="ventes_compresse";
run;
quit;
1
/* Établit une connexion CAS (à adapter à votre environnement) */
2
LIBNAME mycas cas caslib=casuser;
3
4
/* Crée une table non compressée pour l'exemple */
5
DATA mycas.ventes_non_compresse;
6
LENGTH produit $20 quantite prix 8;
7
INPUT produit $ quantite prix;
8
DATALINES;
9
Pomme 101.50
10
Banane 50.75
11
Orange 121.20
12
;
13
RUN;
14
15
/* Crée une copie compressée de la table 'ventes_non_compresse' */
16
DATA mycas.ventes_compresse (compress=yes);
17
SET mycas.ventes_non_compresse;
18
RUN;
19
20
/* Affiche les propriétés de la table compressée (y compris la compression) */
Explanation : This example shows how to add new rows to an already compressed CAS table. The `append=yes` option is used in the DATA Step. New rows, even if not explicitly compressed in the append DATA Step, will be automatically compressed by the CAS server because the `mycas.ventes_compresse` table is already defined as compressed. This is demonstrated by the absence of the `compress=yes` option in the append DATA Step.
Copied!
/* Établit une connexion CAS (à adapter à votre environnement) */
libname mycas cas caslib=casuser;
/* Assurez-vous que la table compressée de l'exemple 1 existe */
proc casutil incaslib="casuser" outcaslib="casuser";
load casdata="ventes_non_compresse" outcasdata="ventes_compresse" replace options=(compress='YES');
run;
/* Ajout de nouvelles lignes à la table compressée existante */
data mycas.ventes_compresse (append=yes);
length produit $20 quantite prix 8;
input produit $ quantite prix;
datalines;
Poire 7 2.10
Kiwi 8 1.80
;
run;
/* Affiche le contenu de la table compressée mise à jour */
proc print data=mycas.ventes_compresse;
run;
1
/* Établit une connexion CAS (à adapter à votre environnement) */
2
LIBNAME mycas cas caslib=casuser;
3
4
/* Assurez-vous que la table compressée de l'exemple 1 existe */
/* Ajout de nouvelles lignes à la table compressée existante */
10
DATA mycas.ventes_compresse (append=yes);
11
LENGTH produit $20 quantite prix 8;
12
INPUT produit $ quantite prix;
13
DATALINES;
14
Poire 72.10
15
Kiwi 81.80
16
;
17
RUN;
18
19
/* Affiche le contenu de la table compressée mise à jour */
20
PROC PRINTDATA=mycas.ventes_compresse;
21
RUN;
3 Code Block
DATA Step Data
Explanation : This example creates a CAS table that is both partitioned and compressed. The `partition=(categorie)` option specifies the partitioning variable, and `compress=yes` enables compression for the in-memory table. New rows added to this table will be automatically partitioned and compressed accordingly. `PROC CASUTIL CONTENTS` with the `details` option allows verification of these attributes.
Copied!
/* Établit une connexion CAS (à adapter à votre environnement) */
libname mycas cas caslib=casuser;
/* Crée une table SAS en local pour l'exemple */
data temp_produits;
length categorie $10 produit $20 quantite prix 8;
input categorie $ produit $ quantite prix;
datalines;
Fruits Pomme 10 1.50
Fruits Banane 5 0.75
Legumes Carotte 20 0.50
Legumes Salade 3 2.00
;
run;
/* Charge et compresse la table, en la partitionnant par 'categorie' */
data mycas.produits_part_comp (partition=(categorie) compress=yes);
set temp_produits;
run;
/* Affiche les propriétés de la table (y compris les informations de partition et de compression) */
proc casutil incaslib="casuser" outcaslib="casuser";
contents casdata="produits_part_comp" details;
run;
quit;
1
/* Établit une connexion CAS (à adapter à votre environnement) */
2
LIBNAME mycas cas caslib=casuser;
3
4
/* Crée une table SAS en local pour l'exemple */
5
DATA temp_produits;
6
LENGTH categorie $10 produit $20 quantite prix 8;
7
INPUT categorie $ produit $ quantite prix;
8
DATALINES;
9
Fruits Pomme 101.50
10
Fruits Banane 50.75
11
Legumes Carotte 200.50
12
Legumes Salade 32.00
13
;
14
RUN;
15
16
/* Charge et compresse la table, en la partitionnant par 'categorie' */
17
DATA mycas.produits_part_comp (partition=(categorie) compress=yes);
18
SET temp_produits;
19
RUN;
20
21
/* Affiche les propriétés de la table (y compris les informations de partition et de compression) */
Explanation : This example uses `PROC CAS` to load a CSV file into memory and compress it directly. The `table.loadTable` method is used, and the `compress=TRUE` option is passed in `casOut` to ensure the table is compressed upon loading. `table.tableInfo` verifies that the table is indeed compressed by displaying details such as compressed and uncompressed size. Note that for a table already present in CAS (e.g., SASHDAT), the behavior of COMPRESS= may vary.
Copied!
/* Établit une connexion CAS (à adapter à votre environnement) */
options casport=5570 cashost="cloud.example.com";
/* Crée une table SASHELP simple à charger */
data _null_;
set sashelp.class;
file "/tmp/class.csv" dlm=',';
if _n_ = 1 then put 'Name,Sex,Age,Height,Weight';
put name sex age height weight;
run;
/* Charge le fichier CSV en mémoire CAS en spécifiant la compression */
proc cas;
session casauto;
table.loadTable /
caslib="casuser",
path="/tmp/class.csv",
casOut={name="class_compresse_cas", compress=TRUE, replace=TRUE},
promote=TRUE;
run;
/* Affiche les informations de la table pour vérifier la compression */
table.tableInfo / caslib="casuser", name="class_compresse_cas", fullinfo=TRUE;
run;
quit;
1
/* Établit une connexion CAS (à adapter à votre environnement) */
2
options casport=5570 cashost="cloud.example.com";
3
4
/* Crée une table SASHELP simple à charger */
5
DATA _null_;
6
SET sashelp.class;
7
file "/tmp/class.csv" dlm=',';
8
IF _n_ = 1THEN put 'Name,Sex,Age,Height,Weight';
9
put name sex age height weight;
10
RUN;
11
12
/* Charge le fichier CSV en mémoire CAS en spécifiant la compression */
While the DATA step is convenient for compression, using PROC CAS or PROC CASUTIL to load data (as seen in Example 4) is generally more efficient for large external files. It allows the CAS server to handle the compression during the initial parallel load, rather than forcing the SAS Compute Server to process it row-by-row before sending it to CAS.
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.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.