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