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


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 Code Block
PROC ASTORE / DATA STEP Data
Copied!
1/* Création d'un modèle simple pour démonstration */
2DATA casuser.iris_data;
3 SET sashelp.iris;
4RUN;
5 
6PROC LOGISTIC DATA=casuser.iris_data outmodel=casuser.my_model;
7 model Species = SepalLength SepalWidth PetalLength PetalWidth;
8RUN;
9 
10/* Téléchargement du modèle ASTORE vers le système de fichiers local */
11PROC ASTORE;
12 download rstore=casuser.my_model;
13 save_file='/tmp/my_model.astore';
14RUN;
2 Code Block
PROC ASTORE / DATA STEP Data
Copied!
1/* Création d'un autre modèle pour démonstration */
2DATA casuser.cars_data;
3 SET sashelp.cars;
4 where Make in ('Audi', 'BMW', 'Mercedes-Benz');
5RUN;
6 
7PROC GLMSELECT DATA=casuser.cars_data outmodel=casuser.auto_model;
8 model Cylinders = Make Type Origin DriveTrain Weight Horsepower MSRP;
9 selection method=stepwise;
10RUN;
11 
12/* Téléchargement du modèle ASTORE avec des options explicites */
13PROC ASTORE;
14 download rstore=casuser.auto_model caslib=casuser;
15 save_file='/tmp/auto_model.astore';
16RUN;
3 Code Block
PROC ASTORE / DATA STEP / %LET Data
Copied!
1/* Création d'un troisième modèle pour démonstration */
2DATA casuser.heart_data;
3 SET sashelp.heart;
4 where STATUS='Alive';
5RUN;
6 
7PROC HPLOGISTIC DATA=casuser.heart_data outmodel=casuser.heart_model;
8 model Cholesterol = Smoking_Status_N BP_Status_N Weight_Status_N;
9RUN;
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 */
15filename _tmp_dir temp;
16DATA _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');
23RUN;
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;
4 Code Block
PROC ASTORE / PROC CAS / DATA STEP Data
Copied!
1/* 1. Création et entraînement d'un modèle simple */
2DATA casuser.sample_data;
3 INPUT x y;
4 DATALINES;
51 10
62 12
73 14
84 16
95 18
10;
11RUN;
12 
13PROC REG DATA=casuser.sample_data outmodel=casuser.my_linear_model;
14 model y = x;
15RUN;
16 
17/* 2. Téléchargement du modèle ASTORE */
18PROC ASTORE;
19 download rstore=casuser.my_linear_model;
20 save_file='/tmp/my_linear_model.astore';
21RUN;
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 */
29PROC ASTORE;
30 upload rstore=casuser.reloaded_model;
31 restore_file='/tmp/my_linear_model.astore';
32RUN;
33 
34/* 5. Utilisation du modèle rechargé pour le scoring */
35DATA casuser.new_data;
36 INPUT x;
37 DATALINES;
386
397
40;
41RUN;
42 
43PROC ASTORE;
44 score rstore=casuser.reloaded_model DATA=casuser.new_data out=casuser.scored_data;
45RUN;
46 
47PROC PRINT DATA=casuser.scored_data;
48RUN;
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