The examples use generated data (datalines) or the SASHELP library, ensuring the autonomy of each code block.
1 Code Block
PROC CASUTIL / PROC PRINT Data
Explanation : This example initializes a CAS session and an associated libname, then loads the first 10 observations of the 'cars' table from the SASHELP library into a CAS table named 'cars_basic'. Finally, it displays the first 10 observations of this CAS table for verification.
Copied!
cas casauto;
libname mycas cas;
caslib _all_ assign;
proc casutil;
load data=sashelp.cars
outcaslib='casuserhdfs'
casout='cars_basic' replace;
run; quit;
proc print data=mycas.cars_basic(obs=10);
title '10 premières observations de SASHELP.CARS dans CAS';
run;
1
cas casauto;
2
LIBNAME mycas cas;
3
caslib _all_ assign;
4
5
PROC CASUTIL;
6
load DATA=sashelp.cars
7
outcaslib='casuserhdfs'
8
casout='cars_basic' replace;
9
RUN; QUIT;
10
11
PROC PRINTDATA=mycas.cars_basic(obs=10);
12
title '10 premières observations de SASHELP.CARS dans CAS';
13
RUN;
2 Code Block
DATA STEP Data
Explanation : After loading the 'cars' table into CAS, this code block creates a new CAS table, 'cars_transformed_mpg', by calculating a new variable 'CombinedMPG' from the MPG_Highway and MPG_City variables. It uses a simple weighting (40% highway, 60% city) and formats the new variable, then displays the first 10 rows.
Copied!
cas casauto;
libname mycas cas;
caslib _all_ assign;
proc casutil;
load data=sashelp.cars
outcaslib='casuserhdfs'
casout='cars_transformed' replace;
run; quit;
data mycas.cars_transformed_mpg(promote=yes);
set mycas.cars_transformed;
CombinedMPG = (MPG_Highway * 0.40) + (MPG_City * 0.60);
format CombinedMPG 5.1;
run;
proc print data=mycas.cars_transformed_mpg(obs=10);
var Make Model CombinedMPG;
title 'MPG Combiné calculé (10 premières observations)';
run;
title 'MPG Combiné calculé (10 premières observations)';
20
RUN;
3 Code Block
DATA STEP / PROC PRINT Data
Explanation : This example first loads 'cars' data into CAS. Then, it executes a complex DATA Step in CAS that filters vehicles to include only 'USA' origin SUVs or 'Asia' origin Sedans. A new variable 'AvgMPG' is calculated. The 'BY Origin Type' processing allows grouping of results, and a message is displayed in the log for each new group to illustrate group processing. Finally, it displays the filtered and processed results.
Copied!
cas casauto;
libname mycas cas;
caslib _all_ assign;
proc casutil;
load data=sashelp.cars
outcaslib='casuserhdfs'
casout='cars_filtered' replace;
run; quit;
data mycas.cars_filtered_grouped(promote=yes);
set mycas.cars_filtered;
by Origin Type;
where (Type = 'SUV' and Origin = 'USA') or (Type = 'Sedan' and Origin = 'Asia');
AvgMPG = mean(MPG_City, MPG_Highway);
if first.Origin then put '---- Nouvelle Origine et Type ----';
put Origin= Type= AvgMPG= Make=;
keep Origin Type Make AvgMPG;
run;
proc print data=mycas.cars_filtered_grouped;
title 'MPG Moyen des SUV Américains et Sedans Asiatiques';
run;
1
cas casauto;
2
LIBNAME mycas cas;
3
caslib _all_ assign;
4
5
PROC CASUTIL;
6
load DATA=sashelp.cars
7
outcaslib='casuserhdfs'
8
casout='cars_filtered' replace;
9
RUN; QUIT;
10
11
DATA mycas.cars_filtered_grouped(promote=yes);
12
SET mycas.cars_filtered;
13
BY Origin Type;
14
where (Type = 'SUV' and Origin = 'USA') or (Type = 'Sedan' and Origin = 'Asia');
15
AvgMPG = mean(MPG_City, MPG_Highway);
16
IF first.Origin THEN put '---- Nouvelle Origine et Type ----';
17
put Origin= Type= AvgMPG= Make=;
18
keep Origin Type Make AvgMPG;
19
RUN;
20
21
PROC PRINTDATA=mycas.cars_filtered_grouped;
22
title 'MPG Moyen des SUV Américains et Sedans Asiatiques';
23
RUN;
4 Code Block
PROC CASUTIL Data
Explanation : This example highlights PROC CASUTIL's table management capabilities. It first creates a small temporary CAS table. Then, it uses 'LIST TABLES' to view available tables, 'CONTENTS' to get detailed information about the temporary table, and 'DROPTABLE' to remove it from CAS memory. A second 'LIST TABLES' command confirms the deletion. This demonstrates the basic lifecycle of an in-memory CAS table.
Copied!
cas casauto;
libname mycas cas;
caslib _all_ assign;
* Création d'une table CAS temporaire pour la démonstration;
data mycas.temp_table(promote=yes);
x = 1;
y = 'Test';
run;
proc casutil;
list tables caslib='casuserhdfs'; * Liste toutes les tables dans la caslib spécifiée;
contents casdata='temp_table'; * Affiche les détails de la table temp_table;
droptable casdata='temp_table'; * Supprime la table temp_table de la mémoire CAS;
list tables caslib='casuserhdfs'; * Vérifie que la table a été supprimée;
run; quit;
1
cas casauto;
2
LIBNAME mycas cas;
3
caslib _all_ assign;
4
5
* Création d'une table CAS temporaire pour la démonstration;
6
DATA mycas.temp_table(promote=yes);
7
x = 1;
8
y = 'Test';
9
RUN;
10
11
PROC CASUTIL;
12
list tables caslib='casuserhdfs'; * Liste toutes les tables dans la caslib spécifiée;
13
contents casdata='temp_table'; * Affiche les détails de la table temp_table;
14
droptable casdata='temp_table'; * Supprime la table temp_table de la mémoire CAS;
15
list tables caslib='casuserhdfs'; * Vérifie que la table a été supprimée;
16
RUN; QUIT;
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.