In my recent blog I focused on the process to deploy models with SAS Model Manager to Hadoop. I mentioned that deploying is a key step for any data scientist and SAS Model Manager assists in bringing the models into production processes. While publishing to Hadoop is an example for batch processing, I would like to focus now on an example where we deploy with real-time scoring execution as the end-goal. One way to do this is by publishing a model to the SAS Micro Analytic Score Service. And just as in my blog where I was publishing to Hadoop, SAS Model Manager can help with that.
But what is SAS Micro Analytics Score Service? SAS Micro Analytic Service or MAS is a memory-resident, high-performance program execution service. As a SAS platform service, it is not available for individual license, but is included in selected SAS solutions (SAS Event Stream Processing, SAS Decision Manager and SAS Model Manager).
Let’s see how MAS works with SAS Model Manager. When SAS Model Manager is installed, a publishing destination for SAS Micro Analytic Service is created automatically -- it’s named “maslocal.” So users can publish models to this SAS Micro Analytic Service publishing destination.
Let’s publish the Interactive_Forest that I was publishing in my blog to Hadoop now to MAS. For that you can open the model in SAS Model manager. We know that the model is in SAS Model Manager because we see in SAS Model Studio that it has been registered in SAS Model Manager:
After opening the model in SAS Model Manager and before starting to publish to a MAS destination, it’s best to validate the score code type of your model. That score code type can be found on the properties tab when opening the model details in SAS Model Manager.
Models with a score code type of DATA step, DS2 package, or DS2 multi-type can be published to the SAS Micro Analytic Service.
When the model that needs to be published is an analytic store, there’s some extra configuration required. This is because the compute service will extract the analytic store (ASTORE) from the analytic store’s CAS table. This table is located in the ModelStore caslib and the compute service copies the ASTORE to the /opt/sas/viya/config/data/modelsvr/astore directory. Each server that hosts the SAS MAS service must have access to a /models/astores/viya file system path which maps to the /opt/sas/viya/config/data/modelsvr/astore directory.
Details for the above remark can be found here.
It should look like this:
Once the conditions are fulfilled, we can publish the selected model:
For some more information around ASTORE and Viya 3.3 have a look here .
With SAS Viya 3.4, there are even more procedures that can create ASTORE models:
After a successful publishing of the model you should see the following:
As mentioned before (and documented in this blog) I published the same model to Hadoop. So the same model is now published to two different target destinations.
After publishing the model to the SAS Micro Analytical Service, we can now call this model via REST API’s from other solutions.
Next step is to consume this model via SAS Viya REST APIs. The API’s are based on resource-oriented URLs. The SAS Viya REST APIs are grouped for convenience into a number of API categories. For now we want to list and execute the MAS deployed models.
The API’s we need for that are coming from the Decision Management group. The documentation can be found on developer.sas.com:
https://developer.sas.com/guides/rest.html
Important note: before start using REST APIs you need to:
Configure your SAS Environment for API Use:
Understand Authentication and Access tokens: a client application that needs to make a REST API request must first be authenticated and obtain an access token. That token is then used on subsequent requests.
Info around this can be found here.
For instance, to retrieve the collection of published MAS modules we can use:
GET /modules
https://developer.sas.com/apis/rest/DecisionManagement/?shell#get-loaded-modules
When doing this request with Postman it looks like this:
Hint: Domain and token are variables you can store within a Postman environment.
Hint: under tests one can write output to Postman console which is sometimes easier to read then the JSON output.
Having the id of the module allows us to find the steps of the scoring module:
GET /modules/{moduleId}/steps
https://developer.sas.com/apis/rest/DecisionManagement/?javascript#get-module-steps
From the response, we filter out the input variables which we will use in the scoring step.
From the response we learn as well that one of the steps is a score step:
Now we have all information to do the scoring of some input variables:
You can re-use those API calls through JavaScript in an html page:
Hey Alan,
thanks for your reply and very good suggestion to create extra article how to execute same model from DS2 & Python code. I will plan to do that and let you know when ready.
Frederik
Please find new article with some DS2 code that is scoring data with same published model in MAS. Python code will follow.
How SAS Model Manager can help in generating DS2 code to run your model in MAS.
Hereby an article how to run with python same published model in MAS.
Hi Frederik - this is a great post , very useful. I would just like to suggest 2 addl things to watch out for (I say this in pain after searching and figuring it out :))
- Those who are trying this in web apps - use JSON.stringify on your final data (the inputs) - execution fails unless everything in that input has proper quotes around the key , values etc. - irritating but necessary - in short - it should be a JSON string, not a JS object.
- the headers are also an important part of this process - especially in an app - include "application/vnd.sas.microanalytic.module.step.input+json" as the content-type
thanks and regards,
Sundaresh
Thanks Sundaresh for the feedback and sorry to hear it took you some time to figure things out, I'm sure you learnt a lot..
Regading the input data here how it was created in the app:
var pl = $('#petallength').val() ;
var pw = $('#petalwidth').val() ;
var sl = $('#sepallength').val() ;
var sw = $('#sepalwidth').val() ;
var dataString = JSON.stringify({"inputs":[{"name":"petallength","value":+pw}, {"name":"petalwidth","value":+pl},{"name":"sepallength","value":+sl}, {"name":"sepalwidth","value":+sw}]});
Regarding the headers it's true what you are saying, the problem is that different REST calls requires different headers, so that was a bit difficult to explain into detail when writing this blog . Here you have some examples of headers used in the web app:
xhr.setRequestHeader('Content-Type', 'application/vnd.sas.models.model.summary');
xhr.setRequestHeader('Content-Type', 'application/vnd.sas.microanalytic.module.step');
xhr.setRequestHeader('Content-Type', 'application/vnd.sas.microanalytic.module.step.input+json');
So hope this helps.
Frederik.
Hi @FrederikV - is the source code for the web app you're referencing available in the SAS github? It would be a useful demo to use & learn from when using this particular aspect of the Viya platform.
thanks
Alan
Hi @alancox , I uploaded the main html file of the test web app on my personal Github.
Let me know if you can access.
Regards,
Frederik
Thanks @FrederikV that's great !
Frederik,
Great write.
At a point you have a web page 'Deploying and Building SAS Applications'. I guess this is what you meant by 'You can re-use those API calls through JavaScript in an html page'.
How or where can you find that page?
Hi Bogdan, there's an exampe on this github project: mas_sample
Frederik
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning and boost your career prospects.