In this blog post I am going to cover the example of importing data into SAS Viya using Cloud Analytic Services (CAS) actions via REST API. For example, you may want to import data into a CASLib via REST API. This means you can perform an import of data outside of the SAS Self-Service Import user interface environment using REST API. Once this data is loaded into CAS it is available for use in applications such as SAS Visual Analytics and SAS Visual Data Builder.
Introduction
To import data into SAS Viya via REST API, you need to make a series of REST API calls:
1. Start CAS Session
2. Load Data into a CASLib
3. End CAS Session
I will walk through these various REST API calls in the sections below using the REST API testing application HTTPRequestor, which is a free add-on to the Mozilla Firefox browser.
Before I perform any of my REST API calls, I need to Base-64 encode my credentials. There are many methods for doing this. One method is to enter this powershell snippet at a Windows command prompt:
powershell "[convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes(\"YourCredentials\"))"
Note: You can use other methods (e.g., Python) to encode your credentials. Use the preferred method by your organization to ensure you are meeting their security protocols. For more info on base64encoding you can visit this site: https://www.base64encode.org/.
Below is the header Authorization information I will be sending with each of my requests.
1. Start CAS Session
First, I need to start a CAS Session. Below is an example request for starting a CAS Session:
POST https://<YourCASServer:Port>/cas/sessions Authorization: Basic <Base-64EncodedCredentials> Content-Type: application/json {}
This request returns the CASSessionUUID needed in the next step.
I construct my request in HTTPRequestor as follows and submit the request:
Here is a screenshot of the raw transaction information.
I need to copy the CAS Session UUID information that was returned for use in the subsequent REST API calls since their CAS Actions must be performed within a CAS Session.
2. Load Data into a CASLib
Now that I have started my CAS session and have its UUID, I can load the table to CAS. Below is an example request for the table.loadTable CAS Action:
POST https://<YourCASServer:Port>/cas/sessions/<CASSessionUUID>/actions/table.load Table Authorization: Basic <Base-64EncodedCredentials> Content-Type: application/json {"casLib":"<InputCASLib>","importOptions":{"fileType":"<FileType>"},"path":"<InputFilePathAndName>", "casout":{"caslib":"<OutputCASLib>","name":"<OutputTableName>","promote":true}}
This request returns a log message: “NOTE: Cloud Analytic Services made the file <InputFilePathAndName> available as table <OutputTableName> in caslib <OutputCASLib>.”
For my example, I will load the SAS data set BASEBALL located in the helpdata CASLib to the Public CASLib and call the CAS Table SAS_BASEBALL. I am copying the data to the Public CASLib to make it more readily available to all CAS users. Let’s first confirm that the SAS_BASEBALL table does not currently exist in the Public CASLib.
I construct my request in HTTPRequestor as follows and submit the request:
Here is a screenshot of the raw transaction information.
Next, I will confirm that the SAS_BASEBALL data set is now loaded in the Public CASLib.
The SAS_BASEBALL data set is now available for use in applications such as SAS Visual Analytics and SAS Visual Data Builder.
3. End CAS Session
Finally, I need to terminate my CAS Session. Below is an example request for the session.endSession CAS Action:
POST https://<YourCASServer:Port>/cas/sessions/<CASSessionUUID>/actions/session.endSession Authorization: Basic <Base-64EncodedCredentials> Content-Type: application/json {}
This request returns a status of 0 indicating there was no error and the CASSessionUUID specified in the request has ended.
I construct my request in HTTPRequestor as follows and submit the request:
Here is a screenshot of the raw transaction information.
Conclusion
These calls can be strung together so you could schedule their execution. For more information on SAS Viya and REST APIs, refer to the following documentation the SAS Cloud Analytics REST API documentation.
9 Comments
I look forward to hearing from you! Awesome blog by the way!
Nice article !
thanks for sharing with us
Thank you soo Much Mam.
I think the below blog will helpful for all my colleagues.
Regards,
veera
Thank for sharing the information Excellent article Cool, Looking ahead to reading a lot Bala Guntipalli Thanks for posting.
Hi,
It can be used for smaller companies as well or only larger enterprises.
Company size does not matter. You just need to have appropriate licensing for the functionality. Contact your SAS sales rep for more information on SAS Viya.
What is the pricing model to use SAS Viya REST API
Thanks for reading my blog post and your interest in SAS Viya. Pricing and packaging questions should be directed to your SAS sales rep.
Hi,
Thank you Mary Kathryn Queen and you share Very elaborated and useful information