BookmarkSubscribeRSS Feed

Add These Tools to Your SAS Viya Developer's Toolbox

Started ‎05-18-2020 by
Modified ‎03-12-2021 by
Views 4,531

Over the last several months I have been involved in the development of applications using SAS Viya. I witnessed a common pattern when integrating the capabilities of CAS and Visual Analytics Reports in web applications using SAS REST APIs.

 

To deploy the application at a user site the following is the typical list of artifacts.

  1. web applications
  2. SAS and CASL programs to execute the analysis
  3. application configuration
  4. One or more CAS tables which are updated at run time based on user actions; usually user input results in running multiple actions and updating of the tables.
  5. pre-defined reports used to visualize the results; the reports might be viewed using SAS Visual Analytics or embedded in the user’s web application using the VA SDK.

 

There are standard ways to deploy items 1 and 2.  This article is focused on two interactive CLI’s (available as npm packages) making the deployment of 3 through 5 simple and repeatable. 

  • @sassoftware/registerclient – use this package to create, delete and list the clientids for three OAuth flows – password, implicit and authorization_code.
  • @sassoftware/viyacaddy – a tool to assist with:
    • import or export SAS Viya VA Reports
    • import data stored as hdat, b7dat or csv
    • import SAS and ds2 code for execution by datastep and scoring actions
    • import astore and sasast files

To facilitate the CI/CD process the tools allow for "batch" mode processing in addition to the CLI.

 

@sassoftware/registerclient

The creation of the clientid is not magic and just requires a couple of API calls. There are several blogs and other documentation on developer.sas.com that discuss how to get these using curl, postman, etc. In particular, refer to Authentication to SAS Viya: a couple of approaches. I always felt that something so basic should be managed either with a UI or a CLI. This CLI attempts to achieve that goal.

 

The registerclient tool is part of the restaf GitHub repository and is accompanied by full documentation.

 

The sample code below launches the app, displays the help text, logs on to SAS, and registers a clientid myapp1.

$ npx @sassoftware/registerclient --env register.env
--------------------------------------
Welcome to @sassoftware/registerclient
Enter help to get a list of all the commands
Use logon command to start your SAS Viya session. User must be an admin.

>> help

  Commands:

    help [command...]         Provides help for a given command.
    exit                      Exits application.
    logon                     Logon to Viya
    list [all]                List clients. Use all option to include system clientids
    config <config>           File containing the configuration for clientid registeration
    new [options] <clientid>  Add a new client with specified name
    delete <clientid>         Delete specified client

>> logon
Enter your userid> sasdemo
Enter your password> ********
Logon Successful
>> add myapp1 -t authorization_code -s mysecret -r http://localhost:8080/myapp
myapp1 has been added
>> list
>>>>>>>>>>>>>>User defined clientids
clientid  : myapp1
        grantTypes: authorization_code,refresh_token
        redirect  : http://localhost:8080/myapp
undefined clientids detected

>>exit

 

@sassoftware/viyacaddy

This module is useful for the import and export of selected contents in SAS Viya. It is designed to address the simple import/export use case discussed earlier in this article. To move large amounts of data and reports please refer to the SAS Viya documentation.

 

The viyacaddy tool is located in the restaf GitHub repository and is accompanied by full documentation.

 

The sample code below launches the app, displays the help text, lists current reports, and imports a report.

 

$ npx @sassoftware/viyacaddy --env register.env
Welcome to @sassoftware/viyacaddy
Enter help to get a list of all the commands
Use logon command to start your SAS Viya session

>> help

  Commands:

    help [command...]                          Provides help for a given command.
    exit                                       Exits application.
    logon                                      Logon to Viya
    tables import [options] <dir> [files...]   Import .sas, .ds2, .sashdat, .sasb7dat, .astore , .sasast, .csv into CAS Tables
    reports list                               List all the VA reports
    reports import [options] <dir> [files...]  Import VA reports
    reports export [options] [files...]        Export VA reports
    caslibs                                    List all active caslibs
    tables list <caslib>                       List tables in a specified caslib

>> logon
Enter your userid> sasdemo
Enter your password> ********
Logon Successful
>> reports list
[
  'Application Activity',
  'CAS Activity',
  'Disk Space',
  'Home Loan Default Demo',
  'SAS Viya Inventory'
]

>> reports import C:\Users\sas\Documents\env testReport.json -f Public
Imports started
Import of C:\Users\sas\Documents\env/testReport.json as report testReport completed

>> reports list
[
  'Application Activity',
  'CAS Activity',
  'Disk Space',
  'Home Loan Default Demo',
  'SAS Viya Inventory'	
  'testReport'
]

>>exit

 

Finally

I hope you find these to be good additions to your toolbox. Please feel free to clone the code and make improvements.

 

Cheers…

 

Version history
Last update:
‎03-12-2021 11:23 AM
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