BookmarkSubscribeRSS Feed

How to Make a Decision Available to Other Applications with Viya 3.4

Started ‎06-27-2019 by
Modified ‎08-22-2019 by
Views 4,799

A real decision is measured by the fact that you have taken a new action. If there is no action you have not truly decided.

 

In SAS Viya 3.4, a decision developed in SAS Decision Manager can be "operationalized", made available to other applications, through MAS. This "openness" enables a whole range of scenarios for many SAS customers. The SAS Micro Analytic Service or MAS is the execution engine. MAS provides the capability to publish a decision into operational environments. This video and post will show you how:


 

 

Concepts

Decision Scenario

For example, you need to assist a SAS customer, a car leasing company buying second-hand cars on the market. The company wishes to take an automatic decision, to BID or NOT TO BID for a car. This is the output of the decision. The decision is dependent on many variables, such as the catalogue price, the make, the year, the mileage. These are the input variables. A decision can be defined by business rules, conditions, analytic models and custom code. You developed and tested a decision for your customer. The customer wants to call the decision from another application.

MAS

You can apply or publish a decision with MAS. What is MAS? The SAS Micro Analytic Service or MAS provides the capability to publish a decision into operational environments. When deployed as part of SAS Decision Manager, MAS is called as a web application with a REST interface by both SAS Decision Manager and by other client applications. MAS provides hosting for DS2 and Python programs and supports a “compile-once, execute-many-times” usage pattern. The REST interface provides easy integration with client applications and adds persistence and clustering for scalability and high availability.

 

Publish the Decision to MAS

In SAS Decision Manager

You developed and tested the decision. Publish:

 

1-Decision.png

Select any image to see a larger version.
Mobile users: To view the images, select the "Full" version at the bottom of the page.

 

Select the maslocal (SAS Micro Analytic Service) publishing destination and click Publish.

(The publishing destination is defined in SAS Environment Manager).

 

 

1-Publishing-Destination-mas.png

You should receive a message that the decision was published successfully. Click on the Scoring Tab and select the Publishing Validation sub-tab.  Click on the link associated with the maslocal destination.  Choose the right table as the Data Source table. Run the validation.

The validation ran successfully. You must then click the results icon associated with the maslocal publishing destination. Go to Code. The code contains a template to run in the Decision REST service.  Any web application, curl, SOAPUI, etc. can execute the service by POSTing a message to the service endpoint (the URL that ends in "/execute").

 

1-Publishing-to-mas-code-1024x367.png

 

 

Prepare the Request

Open Notepad++.

Open a new file and copy the service endpoint URI: 

Replace intviya01.race.sas.com with your server name. Open a new file and copy the line containing the decision manager internal request body:
dcm_internal_requestBody = '{""version"":1,""inputs"":[{""name"":""BLUEBOOKPRICE_"",""value"":""{{BLUEBOOKPRICE}}""},{""name"":""CURRENTBID_"",""value"":""{{CURRENTBID}}""},{""name"":""MAKE_"",""value"":""{{MAKE}}""},{""name"":""MILES_"",""value"":""{{MILES}}""},{""name"":""MODEL_"",""value"":""{{MODEL}}""},{""name"":""ORIGINALINVOICE_"",""value"":""{{ORIGINALINVOICE}}""},{""name"":""ORIGINALMSRP_"",""value"":""{{ORIGINALMSRP}}""},{""name"":""VIN_"",""value"":""{{VIN}}""},{""name"":""YEAR_"",""value"":""{{YEAR}}""},{""name"":""STATE_"",""value"":""{{STATE}}""}]}';

Delete the first part until first {
Go to the end of the file and delete ‘;
Replace the values {{ }} with an accepted data type e.g. {{BLUEBOOKPRICE}} with 5000 or {{MAKE}} with Buick until you arrive at:
{"version":1,"inputs":[{"name":"BLUEBOOKPRICE_","value":50000},{"name":"CURRENTBID_","value":40000},{"name":"MAKE_","value":"Buick"},{"name":"MILES_","value":50000},{"name":"MODEL_","value":"Buick"},{"name":"ORIGINALINVOICE_","value":100000},{"name":"ORIGINALMSRP_","value":91000},{"name":"VIN_","value":"ABCDEF5576868"},{"name":"YEAR_","value":2015},{"name":"STATE_","value":"PA"}]}

This is the body of the request you can pass in the API.

 

Install POSTMAN

Only if you do not have it in your Google Chrome browser: go to Chrome webstore and Add the Postman Extension to Chrome Open Postman. You can Skip registration.

 

Pre-requisites:

There are many options. One of them is to obtain and use a Viya access token. You need to read and execute the instructions in: Authenticate to SAS Viya first.

 

Make a POST Request to Decision Manager

 

Open Postman. In the upper right-hand corner where you see “No environment” select “Manage environments”.

5-Viya-manage-environments-300x116.png

 

Create a new environment and give it a name (e.g.: Viya34).
Set the Key to “authtoken” and in the value, paste the “authtoken” you obtained previously:

 

5-Viya-manage-environments-acces-token-1024x625.png

 

Finally, click “Add” and “Close” the Manage environments window. Return to the main page and prepare a new request. Select POST at the left. Set Environment at your top right to Viya34 .

In the Authorizations tab, select: “No Auth”
.

Return to the main page and prepare a new request.

Select POST at the left. Set Environment from the right to Viya34 .

In the Authorizations tab, select: “No Auth”:

 

6-REST-API-to-Decision-Manager-via-MAS-1024x320.png

 

In the Headers tab create:

Authorization  “bearer {{authtoken}}”

Accept application/json

Content type application/json;charset=utf-8

 

6-REST-API-to-Decision-Manager-via-MAS-Headers-1024x343.png

 

In the Body: paste the json request you prepared in the Body. It has to look like:
{"version":1,"inputs":[{"name":"BLUEBOOKPRICE_","value":50000},{"name":"CURRENTBID_","value":40000},{"name":"MAKE_","value":"Buick"},{"name":"MILES_","value":50000},{"name":"MODEL_","value":"Buick"},{"name":"ORIGINALINVOICE_","value":100000},{"name":"ORIGINALMSRP_","value":91000},{"name":"VIN_","value":"ABCDEF5576868"},{"name":"YEAR_","value":2015},{"name":"STATE_","value":"PA"}]}

6-REST-API-to-Decision-Manager-via-MAS-Body-1024x275.png

 

If everything was done correctly you should be able to POST the inputs and receive the outputs of the executed Decision.

The REST API decision response comes back into the body: the Decision is executed over MAS (e.g.: 'Bid on the Car!'):

 

6-REST-API-to-Decision-Manager-via-MAS-Response-1024x469.png

 

Authenticate to SAS Viya: Register a Client ID

 

If you feel confused about the whole process, you should start from here: Joe Furbee explains Authentication to Viya.

Option 1 is to use the command line interface and probably the easiest. Option 2 is to use sas code. Option 3 is to use python code. There are too many options: please pick the the weapon of your choice: CLI, curl, sas, python, etc.

 

References

 

Interested in learning more about SAS Decision Manager 5.2? The documentation is a good place to start.

The SAS Micro Analytic Service has a layered architecture described in depth in the MAS documentation.

Conclusions

You gained an overview of what a decision is: rules combined with models and custom code. The decision developed in SAS Decision Manager can then be "operationalized" in the application of your choice, through MAS. This "openness" enables a whole range of scenarios for many SAS customers.

 

Thank you for your time reading this post. If you have tried working with decisions and published them, please share your experiences via the comment box.

Version history
Last update:
‎08-22-2019 11:48 PM
Updated by:
Contributors

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

Free course: Data Literacy Essentials

Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning  and boost your career prospects.

Get Started

Article Tags