BookmarkSubscribeRSS Feed

Intelligent Decisioning: Update a Global Variable via REST

Started ‎09-30-2021 by
Modified ‎09-30-2021 by
Views 5,865

Global variables have existed in Intelligent Decisioning since the 5.5 release. Lookup tables have existed from the beginning. I mention lookup tables and global variables together because they are more or less the same thing. Both are implemented as hash objects in MAS and formats (or in-line conditional logic code) in CAS. For the most part, a global variable is just a one row lookup table.

 

sf_1_globVar-1024x606.png

 

Global Variable Example

 

 

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

 

So, naturally people's first reaction to seeing global variables is the same as their first reaction to seeing lookup tables. They want to update them programmatically, without using the SID user interface. So let's do that here with REST...

.

Find the global variable URI

First, we'll need to locate our global variable's universal resource identifier. We could do this programmatically but we'll just look it up in the Viya UI to get a little context. As, the image below shows, you can find the URI by editing the global variable and looking on the versions tab. Note that, for this exercise, we want the global variable URI, not the version ("revision") URI.

 

When we update a global variable, the "Displayed Version" will be updated.

sf_2_globVarURI-1-1024x375.png

 

GET the Global Variable ETag

Next, we need to perform a GET request on the global variable to obtain its current ETag. We need the ETag when we perform the update in the next step. REST uses the ETag to help avoid update collisions.

 

Note that we use the global variable URI, /referenceData/globalVariables/2744cc6d-53bf-490a-8dc7-352dead40ace, in the GET request:

 

GET /referenceData/globalVariables/2744cc6d-53bf-490a-8dc7-352dead40ace/ HTTP/1.1
Host: yourViyaHost.comp.com:443
Accept: application/json
Content-Type: application/json;charset=utf-8
Authorization: Bearer XXXXXXXXXXXXXXXXXXXXXXXXX
Cookie: sas-ingress-nginx=6e50bb65648b4904ca91085f11bee901

 

The ETag is returned in the response header, shown below in Postman.

 

sf_3_globVarETag.png

 

 

Update (PUT) the Global Variable

With both the URI and the ETag, we can now update the global variable. The HTTP request is below. Note the following:

 

  • The request uses an HTTP PUT.
  • The ETag is used in the If-Match request header element.
  • The request body only requires a few fields from the full global variable schema.
  • The request body changes the global variable value from 1.19 (shown above) to 1.2.
PUT /referenceData/globalVariables/2744cc6d-53bf-490a-8dc7-352dead40ace/ HTTP/1.1
Host: yourViyaHost.comp.com:443
Accept: application/json
Content-Type: application/json;charset=utf-8
If-Match: "ktorw3bn"
Authorization: Bearer XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Cookie: sas-ingress-nginx=6ff3a6db3117ea6c83b58f72ff5d473a
Content-Length: 104

{
  "name": "eurusa",
  "description": "eurusa",
  "defaultValue": 1.2,
  "dataType": "decimal"
}

 

And we then we can see that value changed in the user interface….

 

sf_4_globVarAfter-1024x346.png

 

Next Steps

.

  • Want to update/add/delete global variables, lookup tables and, more without using the UI? Check out the Viya REST API at developer.sas.com. .
  • So now that we've updated the global variable, we'll, of course, have to re-activate it. You can see the API doc for that here and we'll cover it in a future post as well. .
  • Of course, we'll want to script this whole process so that we can easily run it when we want. We can do that in SAS with PROC HTTP as well as a host of other languages including Python.
Version history
Last update:
‎09-30-2021 04:12 PM
Updated by:
Contributors

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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 Labels
Article Tags