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.
| Parameter | Description |
|---|---|
| externalCaslib | Specifies the caslib that contains the connection details for the external data source. |
| externalOptions | Defines 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. |
| modelName | The name of the model to be copied. This name must exist in the source model table. This is a required parameter. |
| modelTable | The source CAS table containing the model to be copied. This is a required parameter. |
| modelOptions | Provides 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. |
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.
| 1 | PROC 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}; |
| 19 | RUN; |
| 20 | QUIT; |
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`).
| 1 | PROC 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"}; |
| 8 | RUN; |
| 9 | QUIT; |
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.
| 1 | PROC 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 | }; |
| 15 | RUN; |
| 16 | QUIT; |
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.
| 1 | PROC 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 | }; |
| 11 | RUN; |
| 12 | QUIT; |
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...
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...
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...