modelPublishing

copyModelExternal

Description

The `copyModelExternal` action allows for the duplication of an analytic model, previously stored in a CAS table, to an external data source. This is a crucial step in model deployment pipelines, enabling models trained in SAS Viya to be executed in different environments like Hadoop, Teradata, or on a simple filesystem. The action requires specifying the source model table and name, along with connection details for the target external system.

modelPublishing.copyModelExternal / externalCaslib="string" externalOptions={extType="DATABRICKS"|"FILESYSTEM"|"HADOOP"|"SINGLESTORE"|"SYNAPSE"|"TERADATA", ...} modelName="string" modelOptions={replace=boolean} modelTable={name="string", caslib="string"};
Settings
ParameterDescription
externalCaslibSpecifies the caslib that contains the connection details for the external data source.
externalOptionsDefines the type and connection parameters for the external data source where the model will be copied. This is a required parameter.
extType(Sub-parameter of externalOptions) Specifies the type of the external data source. Supported values include DATABRICKS, FILESYSTEM, HADOOP, SINGLESTORE, SYNAPSE, and TERADATA.
modelNameThe name of the model to be copied. This name must exist in the source model table. This is a required parameter.
modelTableThe source CAS table containing the model to be copied. This is a required parameter.
modelOptionsProvides additional options for the copy operation.
replace(Sub-parameter of modelOptions) When set to TRUE, an existing model with the same name at the destination will be overwritten. Default is TRUE.
modelDir(Sub-parameter of externalOptions for extType="FILESYSTEM") Specifies the root folder where the model directory is created.
modelDatabase(Sub-parameter of externalOptions for extType="HADOOP", "DATABRICKS", "SYNAPSE") Specifies the database or schema name in the external system where the model table will be created.
server(Sub-parameter of externalOptions for extType="TERADATA") The server name or IP address for the Teradata database connection.
database(Sub-parameter of externalOptions for extType="TERADATA") The name of the Teradata database to connect to.
username(Sub-parameter of externalOptions for extType="TERADATA") The username for authenticating with the Teradata database.
password(Sub-parameter of externalOptions for extType="TERADATA") The password for the specified username.
Data Preparation View data prep sheet
Creating and Saving a Decision Tree Model

To use `copyModelExternal`, a model must first exist in a CAS table. This code trains a simple decision tree model on the `iris` dataset, creates an analytic store, and then saves that store into a CAS table named `myModelTable`. This table will be the source for subsequent copy operations.

Copied!
1PROC CAS;
2 LOADACTIONSET "decisionTree";
3 LOADACTIONSET "aStore";
4 
5 /* Load sample data and promote it to global scope */
6 loadTable / caslib="casuser" path="iris.sashdat" casout={name="iris", replace=true, promote=true};
7 
8 /* Train a decision tree model and save its state */
9 decisionTree.dtreeTrain /
10 TABLE={name="iris"}
11 target="Species"
12 inputs={"SepalLength", "SepalWidth", "PetalLength", "PetalWidth"}
13 savestate={name="myModelStore", replace=true};
14 
15 /* Save the analytic store to a CAS table */
16 aStore.save /
17 rstore={name="myModelStore"}
18 TABLE={name="myModelTable", replace=true};
19RUN;
20QUIT;

Examples

This example copies the model named 'myModelStore' from the `myModelTable` CAS table to a directory on the server's filesystem. It assumes a PATH-based CASLIB named `myExtFS` has been configured, pointing to a writable directory (e.g., `/path/to/external/models`).

SAS® / CAS Code Code awaiting community validation
Copied!
1PROC CAS;
2 LOADACTIONSET "modelPublishing";
3 modelPublishing.copyModelExternal /
4 modelTable={name="myModelTable", caslib="casuser"}
5 modelName="myModelStore"
6 externalCaslib="myExtFS" /* Assumes myExtFS is a PATH caslib */
7 externalOptions={extType="FILESYSTEM", modelDir="/models"};
8RUN;
9QUIT;
Result :
The action creates a directory named 'myModelStore' inside the path associated with `myExtFS`, within a subdirectory named 'models'. This new directory will contain the files that constitute the analytic model, ready for use outside of CAS.

This example demonstrates copying the 'myModelStore' model to a Teradata database. It specifies the Teradata server, database, credentials, and the target model table within `externalOptions`. The `replace=true` option in `modelOptions` ensures that if a model with the same name already exists in the target Teradata table, it will be overwritten.

SAS® / CAS Code Code awaiting community validation
Copied!
1PROC CAS;
2 LOADACTIONSET "modelPublishing";
3 modelPublishing.copyModelExternal /
4 modelTable={name="myModelTable", caslib="casuser"}
5 modelName="myModelStore"
6 modelOptions={replace=true}
7 externalOptions={
8 extType="TERADATA",
9 server="my_teradata_server",
10 username="my_user",
11 password="my_password",
12 database="production_db",
13 modelTable={name="teradata_models_table", schema="models_schema"}
14 };
15RUN;
16QUIT;
Result :
The model 'myModelStore' is copied into the 'teradata_models_table' within the 'models_schema' schema in the specified Teradata database. If the table or model already existed, it would be replaced. A success status is returned in the results.

This example copies the 'myModelStore' model to a Hadoop environment. It uses an existing external CASLIB named `myHadoopCaslib` that is pre-configured for Hadoop connectivity. The model will be stored in the 'published_models' database within Hadoop.

SAS® / CAS Code Code awaiting community validation
Copied!
1PROC CAS;
2 LOADACTIONSET "modelPublishing";
3 modelPublishing.copyModelExternal /
4 modelTable={name="myModelTable", caslib="casuser"}
5 modelName="myModelStore"
6 externalCaslib="myHadoopCaslib" /* Assumes myHadoopCaslib is a HADOOP caslib */
7 externalOptions={
8 extType="HADOOP",
9 modelDatabase="published_models"
10 };
11RUN;
12QUIT;
Result :
The action copies the model to the specified Hadoop environment. A new table representing the model will be created within the 'published_models' Hive database, and the action log will confirm the successful copy operation.

FAQ

What is the purpose of the modelPublishing.copyModelExternal action?
What are the required parameters for the copyModelExternal action?
How do I specify the source model to be copied?
How do I define the destination for the model in an external database?
Can I overwrite an existing model in the external database?
What types of external databases are supported by the `extType` parameter?
What specific parameters are needed when copying a model to Teradata (extType='TERADATA')?
What is the main parameter required when the external type is 'FILESYSTEM'?

Associated Scenarios

Use Case
Standard Deployment of CLV Model to Hadoop

A large retail chain has developed a Customer Lifetime Value (CLV) model in SAS Viya. To integrate this with their nightly batch processing pipelines which run on a Data Lake, t...

Use Case
High-Frequency Update of Fraud Model in Teradata

A financial institution updates its Fraud Detection model weekly to adapt to new attack vectors. The model must be pushed to a Teradata appliance used for high-volume transactio...

Use Case
Edge Case: Invalid Configuration for Filesystem Export

An R&D engineer is attempting to archive an experimental model to a local filesystem for offline analysis. They are unfamiliar with the API and omit the mandatory directory path...