Type : CREATION_INTERNE
The examples use generated data (datalines) or SASHELP to create simple models for demonstration purposes, then download these models. No unprovided external files are required.
| 1 | /* Création d'un modèle simple pour démonstration */ |
| 2 | DATA casuser.iris_data; |
| 3 | SET sashelp.iris; |
| 4 | RUN; |
| 5 | |
| 6 | PROC LOGISTIC DATA=casuser.iris_data outmodel=casuser.my_model; |
| 7 | model Species = SepalLength SepalWidth PetalLength PetalWidth; |
| 8 | RUN; |
| 9 | |
| 10 | /* Téléchargement du modèle ASTORE vers le système de fichiers local */ |
| 11 | PROC ASTORE; |
| 12 | download rstore=casuser.my_model; |
| 13 | save_file='/tmp/my_model.astore'; |
| 14 | RUN; |
| 1 | /* Création d'un autre modèle pour démonstration */ |
| 2 | DATA casuser.cars_data; |
| 3 | SET sashelp.cars; |
| 4 | where Make in ('Audi', 'BMW', 'Mercedes-Benz'); |
| 5 | RUN; |
| 6 | |
| 7 | PROC GLMSELECT DATA=casuser.cars_data outmodel=casuser.auto_model; |
| 8 | model Cylinders = Make Type Origin DriveTrain Weight Horsepower MSRP; |
| 9 | selection method=stepwise; |
| 10 | RUN; |
| 11 | |
| 12 | /* Téléchargement du modèle ASTORE avec des options explicites */ |
| 13 | PROC ASTORE; |
| 14 | download rstore=casuser.auto_model caslib=casuser; |
| 15 | save_file='/tmp/auto_model.astore'; |
| 16 | RUN; |
| 1 | /* Création d'un troisième modèle pour démonstration */ |
| 2 | DATA casuser.heart_data; |
| 3 | SET sashelp.heart; |
| 4 | where STATUS='Alive'; |
| 5 | RUN; |
| 6 | |
| 7 | PROC HPLOGISTIC DATA=casuser.heart_data outmodel=casuser.heart_model; |
| 8 | model Cholesterol = Smoking_Status_N BP_Status_N Weight_Status_N; |
| 9 | RUN; |
| 10 | |
| 11 | /* Définir le chemin de téléchargement via une macro-variable */ |
| 12 | %let download_path = /tmp/models/heart_model.astore; |
| 13 | |
| 14 | /* Vérifier l'existence du répertoire de destination et télécharger */ |
| 15 | filename _tmp_dir temp; |
| 16 | DATA _null_; |
| 17 | rc = fcreate("&download_path", 'f'); |
| 18 | IF rc = 0 THEN DO; |
| 19 | call symputx('dir_exists', '1'); |
| 20 | rc = fdelete("&download_path"); |
| 21 | END; |
| 22 | ELSE call symputx('dir_exists', '0'); |
| 23 | RUN; |
| 24 | |
| 25 | %IF &dir_exists. = 1 %THEN %DO; |
| 26 | PROC ASTORE; |
| 27 | download rstore=casuser.heart_model caslib=casuser; |
| 28 | save_file="&download_path"; |
| 29 | RUN; |
| 30 | %put Modèle 'heart_model' téléchargé avec succès vers &download_path.; |
| 31 | %END; |
| 32 | %ELSE %DO; |
| 33 | %put ERREUR: Le chemin de téléchargement '&download_path' est invalide ou le répertoire n'existe pas/n'est pas accessible.; |
| 34 | %END; |
| 1 | /* 1. Création et entraînement d'un modèle simple */ |
| 2 | DATA casuser.sample_data; |
| 3 | INPUT x y; |
| 4 | DATALINES; |
| 5 | 1 10 |
| 6 | 2 12 |
| 7 | 3 14 |
| 8 | 4 16 |
| 9 | 5 18 |
| 10 | ; |
| 11 | RUN; |
| 12 | |
| 13 | PROC REG DATA=casuser.sample_data outmodel=casuser.my_linear_model; |
| 14 | model y = x; |
| 15 | RUN; |
| 16 | |
| 17 | /* 2. Téléchargement du modèle ASTORE */ |
| 18 | PROC ASTORE; |
| 19 | download rstore=casuser.my_linear_model; |
| 20 | save_file='/tmp/my_linear_model.astore'; |
| 21 | RUN; |
| 22 | |
| 23 | /* 3. Déconnexion et reconnexion à une nouvelle session CAS (simulée) */ |
| 24 | /* Dans un environnement réel, cela impliquerait de fermer la session courante et d'en ouvrir une nouvelle */ |
| 25 | /* Pour cet exemple, nous allons simplement simuler en chargeant le modèle dans la même session */ |
| 26 | /* et en utilisant une nouvelle 'nom_session_virtuelle' */ |
| 27 | |
| 28 | /* 4. Chargement du modèle depuis le système de fichiers local vers une nouvelle 'session' CAS */ |
| 29 | PROC ASTORE; |
| 30 | upload rstore=casuser.reloaded_model; |
| 31 | restore_file='/tmp/my_linear_model.astore'; |
| 32 | RUN; |
| 33 | |
| 34 | /* 5. Utilisation du modèle rechargé pour le scoring */ |
| 35 | DATA casuser.new_data; |
| 36 | INPUT x; |
| 37 | DATALINES; |
| 38 | 6 |
| 39 | 7 |
| 40 | ; |
| 41 | RUN; |
| 42 | |
| 43 | PROC ASTORE; |
| 44 | score rstore=casuser.reloaded_model DATA=casuser.new_data out=casuser.scored_data; |
| 45 | RUN; |
| 46 | |
| 47 | PROC PRINT DATA=casuser.scored_data; |
| 48 | RUN; |