Published on :
Général CREATION_INTERNE

Sans titre

This code is also available in: Deutsch Español Français
Awaiting validation
Data Analysis

Type : CREATION_INTERNE


Examples use generated data (datalines) or datasets from the SASHELP library, ensuring their autonomy.

1 Code Block
DATA STEP / PROC CASUTIL Data
Copied!
1LIBNAME mycas cas;
2 
3/* Crée un jeu de données SAS dans la bibliothèque WORK */
4DATA work.sample_data;
5 SET sashelp.class;
6 keep name sex age;
7RUN;
8 
9/* Charge le jeu de données SAS dans CAS (caslib par défaut: CASUSER) */
10PROC CASUTIL;
11 load casdata="sample_data" casout="sample_data_cas" replace;
12RUN;
13 
14/* Vérifie la table chargée dans CAS */
15PROC CAS;
16 TABLE.tableinfo RESULT=info / name="sample_data_cas" caslib="CASUSER";
17 PRINT info;
18QUIT;
2 Code Block
DATA STEP / PROC CASUTIL Data
Copied!
1LIBNAME mycas cas;
2 
3/* Création d'un jeu de données SAS local à charger */
4DATA work.orders_local;
5 INPUT OrderID Customer $ Amount;
6 DATALINES;
71001 Alice 250.00
81002 Bob 120.50
91003 Alice 300.00
101004 Charlie 80.25
11;
12RUN;
13 
14/* Charge le jeu de données SAS dans une caslib spécifique et le promeut */
15PROC CASUTIL;
16 load casdata="orders_local" casout="orders_cas" caslib="CASUSER" promote replace;
17RUN;
18 
19/* Vérification de la table promue dans CAS */
20PROC CAS;
21 TABLE.tableinfo RESULT=info / name="orders_cas" caslib="CASUSER";
22 PRINT info;
23QUIT;
3 Code Block
PROC FORMAT / DATA STEP / PROC CASUTIL Data
Copied!
1LIBNAME mycas cas;
2 
3/* Définition d'un format personnalisé pour une variable */
4PROC FORMAT;
5 value $statusfmt 'A' = 'Actif'
6 'I' = 'Inactif'
7 other = 'Inconnu';
8RUN;
9 
10/* Création d'un jeu de données SAS avec une variable à formater */
11DATA work.employees_local;
12 INPUT EmpID Name $ STATUS $;
13 FORMAT STATUS $statusfmt.; /* Applique le format */
14 DATALINES;
15201 John A
16202 Jane I
17203 Mike A
18204 Sara X
19;
20RUN;
21 
22/* Chargement du jeu de données formaté dans CAS */
23PROC CASUTIL;
24 load casdata="employees_local" casout="employees_cas" caslib="CASUSER" replace;
25RUN;
26 
27/* Vérification et affichage pour voir le format appliqué */
28PROC CAS;
29 TABLE.fetch RESULT=r / TABLE={name="employees_cas", caslib="CASUSER"};
30 PRINT r.Fetch;
31QUIT;
4 Code Block
DATA STEP / PROC CASUTIL / PROC CAS (Actions CAS) Data
Copied!
1LIBNAME mycas cas;
2 
3/* Crée un sous-ensemble du jeu de données SASHELP.CLASS avec un filtre */
4DATA work.filtered_class_local;
5 SET sashelp.class (where=(age >= 12));
6 keep name sex age;
7RUN;
8 
9/* Charge le sous-ensemble dans CAS */
10PROC CASUTIL;
11 load casdata="filtered_class_local" casout="filtered_class_cas" caslib="CASUSER" replace;
12RUN;
13 
14/* Utilise une action CAS (simple.summary) pour effectuer une agrégation distribuée */
15PROC CAS;
16 SIMPLE.summary RESULT=summary_res /
17 TABLE={name="filtered_class_cas", caslib="CASUSER"},
18 groupby={"sex"},
19 inputs={"age"};
20 PRINT summary_res;
21QUIT;
22 
23/* Nettoyage : suppression des tables CAS créées (facultatif) */
24PROC CASUTIL;
25 droptable casdata="sample_data_cas" caslib="CASUSER";
26 droptable casdata="orders_cas" caslib="CASUSER";
27 droptable casdata="employees_cas" caslib="CASUSER";
28 droptable casdata="filtered_class_cas" caslib="CASUSER";
29RUN;
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.