This functionality of the ASTORE procedure facilitates model lifecycle management. After training a model on CAS (for example, with PROC NNET, PROC FOREST, etc.) and saving it as an analytical store, it may be necessary to move it from the CAS server to a local environment for various reasons: scoring on local data without a CAS connection, archiving, or integration into client applications. Downloading preserves the model's structure and weights for later use. The command requires identifying the model on the CAS server (caslib and model name) and specifying the local destination path. It is crucial to ensure that the local path is accessible and that permissions are sufficient to write the file.
Data Analysis
Type : CREATION_INTERNE
The examples simulate the existence of an ASTORE model on the CAS server and demonstrate download operations. The data required for the examples are generated internally or assumed to exist in SASHELP.
1 Code Block
PROC ASTORE Data
Explanation : This example illustrates the simplest download of an ASTORE model. It first creates a dummy ASTORE model on the CAS server (in the 'mycaslib' caslib). Then, the PROC ASTORE procedure with the DOWNLOAD statement is used to transfer this model to the local file system, specified by 'casfile'. The './' path indicates the current working directory of the SAS session.
Copied!
/* Étape 1: Préparation - S'assurer qu'un modèle ASTORE existe sur CAS */
/* Cette étape est à des fins de démonstration. En pratique, un modèle serait déjà entraîné. */
/* Créons une table CAS simple, puis un store bidon */
proc cas;
session casauto;
table.addCaslib / caslib='mycaslib' path='/tmp' datasource={srctype='path'};
data _null_;
file caslib='mycaslib' '/tmp/my_simple_model.sashdat';
put 'MODEL_HEADER_INFO';
put 'MODEL_BINARY_CONTENT';
run;
session.upload / caslib='mycaslib' path='/tmp/my_simple_model.sashdat' casout={name='mySimpleModel', replace=TRUE};
quit;
/* Étape 2: Téléchargement du modèle ASTORE vers le système de fichiers local */
/* Le fichier sera sauvegardé dans le répertoire de travail actuel de SAS. */
proc astore;
download caslib="mycaslib" name="mySimpleModel" casfile="./mySimpleModel.astore";
run;
1
/* Étape 1: Préparation - S'assurer qu'un modèle ASTORE existe sur CAS */
2
/* Cette étape est à des fins de démonstration. En pratique, un modèle serait déjà entraîné. */
3
/* Créons une table CAS simple, puis un store bidon */
Explanation : This example demonstrates the use of the 'REPLACE' option in the DOWNLOAD statement, which allows replacing an existing file on the local file system without generating an error. It reuses the dummy model concept and specifies the local destination path with the replace option.
Copied!
/* Étape 1: Préparation - Assurer l'existence d'un modèle ASTORE sur CAS */
/* Réutilisons le modèle de l'exemple précédent ou créons-en un nouveau */
proc cas;
session casauto;
table.addCaslib / caslib='mycaslib' path='/tmp' datasource={srctype='path'};
data _null_;
file caslib='mycaslib' '/tmp/another_model.sashdat';
put 'MODEL_HEADER_INFO_V2';
put 'MODEL_BINARY_CONTENT_V2';
run;
session.upload / caslib='mycaslib' path='/tmp/another_model.sashdat' casout={name='anotherModel', replace=TRUE};
quit;
/* Étape 2: Téléchargement du modèle ASTORE, en écrasant un fichier local existant */
/* L'option REPLACE assure que le fichier local sera mis à jour. */
proc astore;
download caslib="mycaslib" name="anotherModel" casfile="./anotherModel.astore" replace;
run;
1
/* Étape 1: Préparation - Assurer l'existence d'un modèle ASTORE sur CAS */
2
/* Réutilisons le modèle de l'exemple précédent ou créons-en un nouveau */
Explanation : This example shows a more realistic scenario where a model is first trained (here, a logistic regression with PROC LOGISTIC) and saved directly as an analytical store on the CAS server. Then, the PROC ASTORE DOWNLOAD statement is used to retrieve this trained model and save it locally. This is useful for inspecting the model or deploying it in an offline environment.
Copied!
/* Étape 1: Connexion au serveur CAS et chargement de données */
options casopts=(timeout=3600);
cas casauto;
caslib _all_ assign;
/* Chargement de données SASHELP dans CAS pour l'entraînement */
data casuser.hmeq_data;
set sashelp.hmeq;
where loan ne . and bad ne .;
run;
/* Étape 2: Entraînement d'un modèle simple (régression logistique) et sauvegarde en ASTORE */
proc logistic data=casuser.hmeq_data;
model bad = loan mortdue yoq;
output out=casuser.predicted_hmeq p=phat;
astore caslib='CASUSER' name='hmeq_logistic_model' label='HMEQ Logistic Model' replace;
run;
/* Étape 3: Téléchargement du modèle ASTORE vers le système de fichiers local */
proc astore;
download caslib="CASUSER" name="hmeq_logistic_model" casfile="./hmeq_logistic_model.astore" replace;
run;
1
/* Étape 1: Connexion au serveur CAS et chargement de données */
2
options casopts=(timeout=3600);
3
cas casauto;
4
caslib _all_ assign;
5
6
/* Chargement de données SASHELP dans CAS pour l'entraînement */
7
DATA casuser.hmeq_data;
8
SET sashelp.hmeq;
9
where loan ne . and bad ne .;
10
RUN;
11
12
/* Étape 2: Entraînement d'un modèle simple (régression logistique) et sauvegarde en ASTORE */
Explanation : This example highlights the behavior of the DOWNLOAD statement when a local file with the same name already exists. The first attempt without the 'REPLACE' option illustrates the necessity of this option to overwrite existing files. The second attempt, with 'REPLACE', demonstrates how to force the download and update of the local file. This example is relevant in a Viya environment where local and CAS file management is common.
Copied!
/* Étape 1: S'assurer de l'existence d'un modèle sur CAS pour le test */
proc cas;
session casauto;
table.addCaslib / caslib='mycaslib' path='/tmp' datasource={srctype='path'};
data _null_;
file caslib='mycaslib' '/tmp/conditional_model.sashdat';
put 'MODEL_CONTENT_V_COND';
run;
session.upload / caslib='mycaslib' path='/tmp/conditional_model.sashdat' casout={name='conditionalModel', replace=TRUE};
quit;
/* Étape 2: Tentative de téléchargement - simule un fichier existant déjà */
/* Crée un fichier bidon local pour simuler un fichier existant */
data _null_;
file './conditionalModel.astore';
put 'OLD_LOCAL_MODEL_CONTENT';
run;
/* Tente de télécharger sans l'option REPLACE (devrait échouer ou avertir) */
proc astore;
download caslib="mycaslib" name="conditionalModel" casfile="./conditionalModel.astore";
run;
/* Étape 3: Téléchargement forcé avec REPLACE */
/* Cette étape réussira, écrasant le fichier local existant. */
proc astore;
download caslib="mycaslib" name="conditionalModel" casfile="./conditionalModel.astore" replace;
run;
/* Nettoyage : Suppression du fichier local et du modèle CAS */
/* x 'rm ./conditionalModel.astore'; */ /* Décommenter si l'exécution en ligne de commande est autorisée */
proc casutil;
delete casdata="conditionalModel" incaslib="mycaslib";
dropcaslib 'mycaslib';
quit;
1
/* Étape 1: S'assurer de l'existence d'un modèle sur CAS pour le test */
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.
« Before downloading, use proc astore; describe caslib="CASUSER" name="yourModel"; run; to check the model size and input requirements. Large models (like deep random forests) can result in multi-gigabyte files that may impact local storage and network transfer times. »
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.