In a SAS Viya environment (as used in this script), the file path specified (/tmp/freqtable.xlsx) refers to the temporary directory of the Compute Server (the pod running the code), not your local PC's hard drive. To view this file, you must navigate to the Server Files in SAS Studio and download it, or use code to move it to a persistent location (like a SAS Content folder) if you want to keep it after the session ends.
Type : CREATION_INTERNE
A CAS table named 'qualifyapps' is internally created using a DATA step with 'datalines' for example data, then loaded into CAS memory via PROC CASUTIL. This approach ensures that the example is autonomous and does not depend on pre-existing external data.
| 1 | /* 1. Création d'une table CAS d'exemple pour la démonstration */ |
| 2 | /* Ceci rend l'exemple autonome, comme exigé. */ |
| 3 | DATA casuser.qualifyapps; |
| 4 | INPUT Credit_Qualification $ Count; |
| 5 | DATALINES; |
| 6 | Bonne 100 |
| 7 | Mauvaise 50 |
| 8 | Inconnue 20 |
| 9 | ; |
| 10 | RUN; |
| 11 | |
| 12 | /* 2. Charger la table en mémoire CAS (si ce n'est pas déjà fait) */ |
| 13 | PROC CASUTIL; |
| 14 | casauto restart; |
| 15 | load casdata="qualifyapps" incaslib="casuser" casout="qualifyapps" replace; |
| 16 | list tables; |
| 17 | QUIT; |
| 18 | |
| 19 | /* 3. Définir le chemin de sortie pour le fichier Excel */ |
| 20 | /* Le chemin /tmp est utilisé ici, assurez-vous qu'il est accessible en écriture */ |
| 21 | filename outfile "/tmp/freqtable.xlsx"; |
| 22 | |
| 23 | /* 4. Ouvrir la destination ODS EXCEL et configurer les options */ |
| 24 | /* - file: spécifie le nom du fichier de sortie. */ |
| 25 | /* - sheet_label: définit le nom de l'onglet dans Excel. */ |
| 26 | /* - embedded_titles/embed_titles_once: gère l'insertion des titres SAS.*/ |
| 27 | ods excel file=outfile |
| 28 | options(sheet_label="CreditQualification" |
| 29 | embedded_titles="yes" |
| 30 | embed_titles_once="yes"); |
| 31 | |
| 32 | /* 5. Exécuter l'action CAS freqTab.freqTab pour générer le tableau de fréquences */ |
| 33 | /* - table: spécifie la table CAS à analyser. */ |
| 34 | /* - weight: la variable de pondération (nombre d'occurrences). */ |
| 35 | /* - tabulate: la variable pour laquelle calculer les fréquences. */ |
| 36 | PROC CAS; |
| 37 | ACTION freqTab.freqTab/ |
| 38 | TABLE='qualifyapps', |
| 39 | weight='Count', |
| 40 | tabulate={'Credit_Qualification'}; |
| 41 | RUN; |
| 42 | |
| 43 | /* 6. Fermer la destination ODS EXCEL pour écrire le fichier */ |
| 44 | ods excel close; |
| 45 | |
| 46 | /* 7. Quitter la session SAS (optionnel, selon l'environnement d'exécution) */ |
| 47 | QUIT; |