neuralNet

annCode

Description

The annCode action generates SAS DATA step scoring code from a trained artificial neural network model. This allows for the deployment of the model outside of the CAS environment, enabling scoring of new data in traditional SAS environments. The generated code can be saved to a CAS table for further use.

neuralNet.annCode <result=results> <status=rc> / code={...}, listNode="ALL" | "HIDDEN" | "INPUT" | "OUTPUT", modelId="string", modelTable={...};
Settings
ParameterDescription
codeRequests that the action produce SAS score code. This parameter allows specifying output options for the generated code, such as the destination table.
listNodeSpecifies which nodes (ALL, HIDDEN, INPUT, OUTPUT) to include in the scored output table. This is particularly useful for autoencoding to reduce input dimensions.
modelIdSpecifies a model ID variable name to be included in the generated DATA step scoring code. By default, this is prefixed with 'ANN_' followed by the target variable name.
modelTableSpecifies the input table that contains the trained artificial neural network model to be used for generating the scoring code.
Data Preparation View data prep sheet
Create Sample Data for Training

This example creates a sample dataset named 'sample_data' with several input variables and a target variable, suitable for training a neural network model.

Copied!
1DATA casuser.sample_data;
2 DO i = 1 to 100;
3 input1 = rand('UNIFORM');
4 input2 = rand('UNIFORM') * 2;
5 input3 = rand('NORMAL', 0, 1);
6 target = (input1 + input2 > 2) + rand('NORMAL')*0.1;
7 OUTPUT;
8 END;
9RUN;

Examples

This example first trains a simple neural network model using the `annTrain` action and stores it in a table named 'my_model'. Then, it uses the `annCode` action to generate the corresponding SAS DATA step scoring code.

SAS® / CAS Code Code awaiting community validation
Copied!
1PROC CAS;
2 neuralNet.annTrain /
3 TABLE={name='sample_data'},
4 inputs={{name='input1'}, {name='input2'}, {name='input3'}},
5 target='target',
6 casOut={name='my_model', replace=true};
7 neuralNet.annCode /
8 modelTable={name='my_model'},
9 code={casOut={name='my_score_code', replace=true}};
10RUN;

This example demonstrates a more detailed workflow. First, a neural network is trained with a specific architecture (one hidden layer with 5 neurons). The trained model is saved to 'my_detailed_model'. Then, `annCode` is used to generate scoring code with a custom model identifier ('MyFirstANN') and saves the code into the 'my_detailed_score_code' CAS table.

SAS® / CAS Code Code awaiting community validation
Copied!
1PROC CAS;
2 neuralNet.annTrain /
3 TABLE={name='sample_data'},
4 inputs={{name='input1'}, {name='input2'}, {name='input3'}},
5 target='target',
6 arch='NEURAL',
7 hidden={{n=5, act='TANH'}},
8 casOut={name='my_detailed_model', replace=true};
9 neuralNet.annCode /
10 modelTable={name='my_detailed_model'},
11 modelId='MyFirstANN',
12 code={casOut={name='my_detailed_score_code', replace=true}};
13RUN;

FAQ

What is the purpose of the annCode action in the Neural Network action set?
How do I specify the neural network model to be used by the annCode action?
What does the 'code' parameter do in the annCode action?
How can I control which nodes are included in the scored output table when using the annCode action?
What is the function of the 'modelId' parameter?

Associated Scenarios

Use Case
Standard Churn Model Scoring Code Generation

A telecom company has trained a neural network to predict customer churn. They need to generate SAS DATA step code to deploy this model in their production scoring environment t...

Use Case
High-Dimensionality Reduction using Autoencoder and `listNode` Parameter

A manufacturing plant uses high-resolution images of its products for quality control. To speed up analysis, they use a neural network autoencoder to reduce the dimensionality o...

Use Case
Edge Case: Scoring Code with Custom Model ID and Missing Values

A financial institution maintains multiple versions of a credit risk model. To avoid confusion in their model inventory, each generated scoring code needs a specific, human-read...