SAS Container Runtime (SCR) allows you to publish SAS decisions as container images in Azure. In this post you will learn how to make use of these images in Azure. Firstly, you can create a container instance, in Azure, from the published image. Secondly, you can score the decision using a simple curl command or Python program.
SAS Container Runtime (SCR, pronounced “soccer”) is available since the SAS Viya version 2021.1.3. You can publish decisions as container images, in Azure, since the 2021.1.4 SAS Viya stable version.
SAS Container Runtime benefits:
The two minutes video shows you how to create an Azure Container Instance from a SCR image and how to score the SAS decision inside, using curl.
From a conceptual perspective, the post discusses the highlighted components:
Select any image to see a larger version.
Mobile users: To view the images, select the "Full" version at the bottom of the page.
The scenario assumes you have already published a SAS decision, with SCR, to an Azure Container Registry (ACR).
Autoauctiondec1_0 is a decision, with a branch, two rule sets and a DS2 code file. The decision recommends you to Bid (or not) on cars auctioned online.
Analytical models supported by SCR (analytical store, DS2) can also be included in the decision.
You can read more about in How to Publish a Decision to Azure with SAS Container Runtime. To configure the Azure publishing destination in SAS, read How to Publish a SAS Model to Azure with SCR: A Start-to-Finish Guide.
The decision has been published as a SCR container image to an Azure Container Registry (ACR) repository.
When you drill-down into the individual image (decision name + version), and then by tag (latest published version), you will notice the SCR container image can be retrieved with a simple docker command.
To score the decision inside a container:
The video above shows you how to create a container instance, called autoauctiondec. To score the model, you will need these elements:
From a functional perspective, the decision is assessing cars and bid data and, telling you if you should bid, or not. The data section contains one record, in json format. To score the model you can write a simple curl command, from a Linux machine. The machine must be able (and allowed) to reach the Azure container instance.
curl --location --request POST 'http://autoauctiondec.eastus.azurecontainer.io:8080/autoauctiondec1_0' --header 'Content-Type: application/json' --header 'Accept: application/json' --data '{
"version":1,
"inputs":[
{"name":"BlueBookPrice","value":80000},
{"name":"CurrentBid","value":90000},
{"name":"Make","value":"Tesla"},
{"name":"Miles","value":5000},
{"name":"Model","value":"X100D"},
{"name":"OriginalInvoice","value":100000},
{"name":"OriginalMSRP","value":100000},
{"name":"state","value":"CA"},
{"name":"VIN","value":"12345678901234562"},
{"name":"Year","value":2017}
]
}'
To format the json response, you can use jq, a JSON processor. You can add it at the end, so that you have:
...}]} ' | jq
The response of the model score comes back in .json format.
In plain language, the decision determines you should bid on this car, and assigns Bid = 1.
Alternative with python:
import http.client
import json
conn = http.client.HTTPConnection("autoauctiondec.eastus.azurecontainer.io:8080")
payload = json.dumps({
"inputs":[
{"name":"BlueBookPrice","value":80000},
{"name":"CurrentBid","value":90000},
{"name":"Make","value":"Tesla"},
{"name":"Miles","value":5000},
{"name":"Model","value":"X100D"},
{"name":"OriginalInvoice","value":100000},
{"name":"OriginalMSRP","value":100000},
{"name":"state","value":"CA"},
{"name":"VIN","value":"12345678901234562"},
{"name":"Year","value":2017}
]
})
headers = {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
conn.request("POST", "/autoauctiondec1_0", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
For the same decision published to MAS, the data input expected would have been:
curl --location --request POST 'https://{{viya_server_host}}:443/microanalyticScore/modules/ autoauctiondec1_0/steps/execute/' --header 'Content-Type: application/json' --header 'Accept: application/json' --data '{
"version":1,
"inputs":[
{"name":"BLUEBOOKPRICE_","value":80000},
{"name":"CURRENTBID_","value":90000},
{"name":"MAKE_","value":"Tesla"},
{"name":"MILES_","value":5000},
{"name":"MODEL_","value":"X100D"},
{"name":"ORIGINALINVOICE_","value":100000},
{"name":"ORIGINALMSRP_","value":100000},
{"name":"STATE_","value":"CA"},
{"name":"VIN_","value":"12345678901234562"},
{"name":"YEAR_","value":2017}
]
}'
If you pass the input data for a MAS request to a SCR container, you will get your response back with null values. You have been warned.
If ever in doubt about your data input format, browse the container:
ls
cd modules
ls
cat _module_definition.json
You will see the exact field names you have to use in your request. These are preceeded by in_out: BlueBookPrice is expected, not BLUEBOOK nor BLUEBOOK_.
You can publish rule sets, independent of decisions. You can score them in a container, in the exact same way.
Not all decision components from SAS Intelligent Decisioning are supported. Read more in the How to Publish a Decision to Azure with SAS Container Runtime, the Caveats paragraph.
All the credits go to my colleague Deva Kumar. Thank you for teaching me how to score a model in Azure.
It is quite easy to create a container instance in Azure, from a SCR container image. Then, you can score the decision using a simple command to call the SCR REST API with curl, python, SAS, etc.
Thank you for your time reading this post. If you liked the post, give it a thumbs up! Please comment and tell us what you think about the new SCR and Azure as a SAS publishing destination.
Find more articles from SAS Global Enablement and Learning here.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning and boost your career prospects.