BookmarkSubscribeRSS Feed

Install and use the SAS Viya CLI on Windows

Started ‎07-26-2023 by
Modified ‎07-26-2023 by
Views 1,710

In this Part 1 of a two-part series, we will go through a beginning-to-end process to install, configure and use the SAS Viya Command-Line interface on Windows. In Part 2, we will install and use the pyviyatools on Windows, which will be a little simpler, once we have done the hard work of completing Part 1.

 

Why do we need guides like this? Is it not all documented already? Well, yes... but...

 

In the SAS Global Enablement and Learning team, we (and people attending our workshops) normally install and use both the SAS Viya CLI and pyviyatools on Linux machines. Even if we want to run these tools from our own Windows laptop or desktop, we generally find it convenient to do so from a Bash shell running in Windows Subsystem for Linux. If this is an option for you, it is really nice. Installation of these tools in Linux is comparatively straightforward, and seems much easier to script than it is on Windows.

 

However, customers whose end users have Windows machines often want to install the SAS Viya CLI and pyviyatools on those Windows machines. Both tool sets do run on Windows, but beginning-to-end instructions for how to set up all the various components and dependencies are hard to find. It seems you have to piece them together from documentation in several different places, which is tedious.

 

This guide is therefore one possible ‘happy path’ for setting these tools up on Windows from scratch. There are a LOT of steps, which may be part of the reason why there are few other guides to the whole procedure. If you have some of the components already, you may find you can skip the corresponding section. But below you can find the complete process. I hope it turns out to be useful.

 

Contents

 

In Part 1 of this guide, we will cover:
  • Dependencies
  • Prerequisites
    • Windows Client Machine
    • PowerShell and Windows Command Prompt are both required
    • Installation directories
  • Install the SAS Viya CLI
    • Installing the SAS Viya CLI is difficult to automate
    • Download SAS Viya CLI using a web browser
    • Install SAS Viya CLI and its plugins
  • Enable SAS Viya CLI to communicate with SAS Viya
    • Chocolatey
    • curl
    • kubectl
    • kubeconfig file
    • Certificates file
  • Define SAS Viya CLI profiles
  • Validate that sas-viya CLI can access your SAS Viya deployment
  • Use the SAS Viya CLI from a Windows command prompt
    • SAS Viya CLI Examples
No doubt this guide could be improved. If you see areas you think are overcomplicated, wrong or unnecessary, or if you have questions about why I chose a particular command or installation method, I would love to hear from you. Leave a comment below or get in touch!

 

Dependencies

 
The following diagram shows how the packages required to use the SAS Viya CLI and pyviyatools depend on each other, for installation and at run time, and how some of them depend on prerequisites.

 

ds_1_Installing-SAS-Viya-CLI-and-pyviyatools-on-Windows-Dependency-tree-1024x537.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.

 

The green boxes are things that we will install if they are not already installed. Really, all the things in green boxes require a Windows client machine, but showing that would not make the diagram any more clear.

 

The SAS Viya CLI has been carefully designed not to have much in the way of dependencies. However, if you have enabled Transport Layer Security for your SAS Viya platform, the Windows machine where the SAS Viya CLI runs must trust the certificates presented by the SAS Viya server in order to communicate with it. This is achieved by providing it with a bundle of trusted CA certificates, shown as ‘certificates file’ in the diagram. SAS Help Center's Command-Line Interface: Preliminary Instructions explain this in more detail. They also explain how to obtain that file using kubectl and a kubeconfig file, steps which are a part of this guide.

 

Since our goal is to install both the SAS Viya CLI and pyviyatools, we may as well use kubectl (a pre-requisite of pyviyatools) to get the necessary certificate file ourselves, rather than just having you provide it as a prerequisite.

 

Your Windows machine may already have some of these tools installed. If you find you already have a component like python3 or git, or you prefer to install it some other way, that is fine. You may need to adapt some of the installation instructions below to adapt for differences between your machine and the more-or-less new Windows VM I used to write the instructions.

 

Prerequisites

 
Pre-requisites are shown as grey boxes in the dependency diagram. This article does not cover how to create:
  • A SAS Viya deployment, in a Kubernetes cluster. Your Kubernetes administrator, SAS Administrator, deployment consultant or service provider sets this up.
    • A kubeconfig file is required to deploy SAS Viya. You could use this kubeconfig file, or another one that your Kubernetes administrator provides, whichever they prefer.
    • When SAS Viya is deployed, a trustedcerts.pem certificates file is created automatically as part of that process, and is stored by the SAS Logon service. No additional steps are required to create this, and we will get a copy of it during the process described in this guide.
  • A username and password that allow you to authenticate to your SAS Viya deployment, preferably as a SAS Administrator. Get this from your SAS Administrator.
  • A Windows client machine on which you can install the chocolatey package manager, curl, kubectl and the sas-viya CLI, and if you continue to part2 (coming soon), python3 and its requests and configobj modules, git and finally pyviyatools.

Windows Client Machine

 
You will need a Windows machine to try installing SAS Viya CLI and pyviyatools. Use your own Windows desktop/laptop if you like and have sufficient permissions.

 

 

PowerShell and Windows Command Prompt are both required

 
I have chosen to use both PowerShell and Windows Command Prompt for this guide, since each is required for certain tasks.

 

PowerShell has better commands (cmdlets) for things like setting environment variables and unzipping .zip archives, and it is likely the shell a modern Windows administrator will be more familiar with. However, I have not yet discovered how to (or if you can) run the sas-viya CLI in PowerShell.

 

I found fewer examples showing how to install packages we need using Windows Command Prompt, so it would take more work to convert these instructions to run solely in a Command Prompt, though I think you could. The SAS Viya CLI and pyviyatools both work in a Command Prompt, and I think it is arguably more familiar to non-Windows administrators.

 

I would love to hear from you if:
  • you know how to get the SAS Viya CLI working in PowerShell (or if you know for sure that you can’t)
  • you can convert all steps in this guide to work in Windows Command Prompt without too much additional complexity

 

Installation directories

 
These instructions put kubectl, a kubeconfig file, the sas-viya CLI executable, and pyviyatools in the following directories:
Tool or file Directory
Kubectl C:\Program Files\kubectl
Kubeconfig file $HOME\.kube\config
SAS Viya certificates $HOME\.certs
SAS Viya CLI executable C:\ViyaHome\CLI
pyviyatools C:\ViyaHome\pyviyatools
But none of them have to be in those directories. You are free to put any of these things in a different directory, as required by your Windows machine’s disk space or permission constraints, or to suit your preferences. Modify references to the path for each component in e.g. environment variables accordingly.

 

Install the SAS Viya CLI

 
In this Part 1 of the guide, we will install the SAS Viya CLI, but also install chocolatey, curl and kubectl, and provide a kubeconfig file so that we can get the certificates file that the SAS Viya CLI needs to trust TLS certificates presented by SAS Viya. If your goal is to set up the SAS Viya CLI only, and not pyviyatools, you can stop at the end of part 1.

ds_3_Installing-SAS-Viya-CLI-and-pyviyatools-on-Windows-Part-1-only-1024x729.png

 

Other readers may want to continue on to part 2, to install pyviyatools on Windows. Since pyviyatools depends on the SAS Viya CLI, and because in part 2. I chose to use the chocolatey package manager to install python and git, you should complete part 1 of this guide first even if your main aim is to install pyviyatools.

 

Preliminary set-up instructions for the SAS Viya CLI can be found in the SAS Help Center documentation at: https://go.documentation.sas.com/doc/en/sasadmincdc/default/calcli/n1e2dehluji7jon1gk69yggc6i28.htm

 

Installing the SAS Viya CLI is difficult to automate

 
Unless you have a tool that can navigate to a web page in a browser and click a button in that web page automatically, you cannot fully automate installation of the SAS Viya CLI. Such tools are commonly used to functionally test web pages (among other things), but most of us don’t have one, and it doesn’t make sense to spend the money or effort setting one up just to script this one step.

 

Without such a tool, you must either:
  1. click a button on a web page popup dialog in your browser, in order to accept the ‘SAS License Agreement for Download’, or
  2. download the SAS Viya CLI executable ahead of time, and provide it e.g. in a volume accessible to scripts which you can run on your Windows client machine.
We prefer option '2' above for our workshop environments. For these instructions, option '1' above is simpler.

 

 

Download SAS Viya CLI using a web browser

 
  1. In a web browser in your Windows client machine, search the web for "SAS Viya CLI download" or browse to https://support.sas.com/downloads/package.htm?pid=2512. I used Chrome on my machine, but any browser should work fine.
  2. Sign in to sas.com.
  3. In the web page that opens once you have signed in, find the download link for ‘sas-viya for Windows’:

ds_4_Table-of-download-links-for-SAS-Viya-CLI.png

 

At the time of writing this was sas-viya-cli-1.21.10-windows.zip, but this is updated quite regularly; you should choose the current version. Click the link to download the .zip file.

 

  1. Read the ‘SAS License Agreement for Download’ and click the ‘Accept’ button if you accept it:

ds_4_5_SAS-License-Agreement-for-Download.png

 

Note: This step cannot currently be automated without software which I think is too expensive or complex to recommend for this use case alone.

 

  1. Since I used Chrome as my browser, the .zip file was automatically downloaded to $HOME\Downloads (aliased as %USERPROFILE%\Downloads if you are using Windows Command Prompt). Other browsers may place the .zip file in another location by default. If they do not save it to your Downloads directory by default, Save As, move or copy it there yourself.

 

Install SAS Viya CLI and its plugins

 
  1. Open a new PowerShell terminal window. It may be convenient to pin it to the Windows Task Bar or Start Menu.
  2. In your PowerShell terminal window, and run this to create a directory to contain the extracted SAS Viya CLI executable, unzip the downloaded file to $HOME\Downloads\sas-viya-cli, and to then copy the sas-viya.exe executable to C:\ViyaHome\CLI:
mkdir C:\ViyaHome\CLI
$files = Get-ChildItem $HOME\Downloads\sas-viya-cli*.zip | select-object -first 1
foreach($f in $files){Expand-Archive $f -DestinationPath C:\ViyaHome\CLI}
Get-ChildItem C:\ViyaHome\CLI

Tip: Scroll the textbox above to the right if necessary.

 

  1. Run this to install the sas-viya CLI plugins – they are automatically installed to a new directory, at $HOME\.sas:
cd C:\ViyaHome\CLI
.\sas-viya plugins install --repo SAS all
  1. Add the sas-viya CLI directory path to your machine’s Path environment variable. In the PowerShell terminal window, run this:
[Environment]::SetEnvironmentVariable("Path",[Environment]::GetEnvironmentVariable("Path", [EnvironmentVariableTarget]::Machine) + ";C:\ViyaHome\CLI", [EnvironmentVariableTarget]::Machine)

Tip: Scroll the textbox above to the right if necessary, to see the whole command.

 

  1. Close the PowerShell terminal window. We will open a new one in the next step, to pick up the change to the machine’s path environment variable.

 

Enable SAS Viya CLI to communicate with SAS Viya

 
We will need to provide a certificates file and set some environment variables before we can use the SAS Viya CLI to connect to our SAS Viya deployment. To get the certificates file, we will set up kubectl and provide a kubeconfig file (see Prerequisites  above) for the Kubernetes cluster where the SAS Viya platform is running. This set of steps is performed in PowerShell.

 

Chocolatey

 
Chocolatey is an open-source command-line package manager for Windows. We will use it to install packages in both Part 1 and part 2 of this guide.

 

The following instructions are based on Chocolatey Software Docs | Setup / Install (https://docs.chocolatey.org/en-us/choco/setup). With the Windows VM I used to develop these instructions, the first attempt at installation results in an error message asking you to restart the machine, and the second attempt at installation succeeds.
  1. Open a new Windows PowerShell terminal window.
  2. Run this command:
Get-ExecutionPolicy
  1. If the response is Unrestricted, continue to next step. If the response is Restricted, then run one of these commands:
Set-ExecutionPolicy AllSigned

or

Set-ExecutionPolicy Bypass -Scope Process
  1. Run this to install Chocolatey. Installation takes several minutes, and at one stage there will be no new console output for several (5-10) minutes:
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))

Tip: Scroll the textbox above to the right if necessary, to see the whole command.

  1. If the previous command finishes by showing the message below (in red – but don’t panic, it’s okay!), do what the message says and reboot your Windows machine:
.NET Framework 4.8 was installed, but a reboot is required.
Please reboot the system and try to install/upgrade Chocolatey again.
At C:\Users\student\AppData\Local\Temp\2\chocolatey\chocoInstall\tools\chocolateysetup.psm1:815 char:11
+ throw ".NET Framework 4.8 was installed, but a reboot is re ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (.NET Framework ...ocolatey again.:String) [], RuntimeException
+ FullyQualifiedErrorId : .NET Framework 4.8 was installed, but a reboot is required.
Please reboot the system and try to install/upgrade Chocolatey again.
  1. Once your Windows machine has restarted, sign in again, and open a PowerShell terminal window again. Re-run the command above to try installing Chocolatey again. This time it should complete in a few seconds, and be successful:

ds_5_Chocolatey-installed-successfully.png

 

curl

 
  1. Run this command in the same PowerShell window to install curl:
choco install curl -y

kubectl

See Install and Set Up kubectl on Windows | Kubernetes for the latest instructions.

  1. Create a directory for the kubectl executable. It does not have to be in C:\Program Files\kubectl, but that path seems logical to me. In the PowerShell terminal window, run this:
mkdir "C:\Program Files\kubectl"
  1. Install kubectl. In the PowerShell terminal window, run this. You should cd to the directory you created in the previous step. And this curl command fetches the current version of kubectl (1.27.2) at the time I wrote this guide. See Install and Set Up kubectl on Windows | Kubernetes for the latest version, as new versions are released frequently. You may need to find the version of Kubernetes your cluster is running, and use a compatible version of kubectl.
cd "C:\Program Files\kubectl"
curl.exe -LO https://dl.k8s.io/release/v1.27.2/bin/windows/amd64/kubectl.exe
  1. Validate kubectl. In the PowerShell terminal window, run this:
& "C:\Program Files\kubectl\kubectl.exe" version --client --output=yaml

Expected output, showing the version of kubectl you just installed:

PS C:\Program Files\kubectl> & "C:\Program Files\kubectl\kubectl.exe" version --client --output=yaml
clientVersion:
  buildDate: "2023-05-17T14:20:07Z"
  compiler: gc
  gitCommit: 7f6f68fdabc4df88cfea2dcf9a19b2b830f1e647
  gitTreeState: clean
  gitVersion: v1.27.2
  goVersion: go1.20.4
  major: "1"
  minor: "27"
  platform: windows/amd64
kustomizeVersion: v5.0.1

PS C:\Program Files\kubectl>
  1. Add the kubectl directory path to your machine’s Path environment variable. In the PowerShell terminal window, run this, if necessary substituting the full path to the directory where you installed kubectl for C:\Program Files\kubectl if you installed it somewhere else:
[Environment]::SetEnvironmentVariable("Path",[Environment]::GetEnvironmentVariable("Path", [EnvironmentVariableTarget]::Machine) + ";C:\Program Files\kubectl", [EnvironmentVariableTarget]::Machine)

Tip: Scroll the textbox above to the right if necessary, to see the whole command.

  1. Close the PowerShell terminal window and open a new one, to pick up the change to the machine’s path environment variable.
  2. Test that kubectl is now in your path. Run this from any directory in the PowerShell command window (it should also work from a Windows command prompt):
kubectl version --client --output=yaml

Expected output, showing the version of kubectl you just installed:

PS C:\Users\student> kubectl version --client --output=yaml
clientVersion:
  buildDate: "2023-05-17T14:20:07Z"
  compiler: gc
  gitCommit: 7f6f68fdabc4df88cfea2dcf9a19b2b830f1e647
  gitTreeState: clean
  gitVersion: v1.27.2
  goVersion: go1.20.4
  major: "1"
  minor: "27"
  platform: windows/amd64
kustomizeVersion: v5.0.1

PS C:\Users\student>

kubeconfig file

 
  1. Create a directory for the kubeconfig file. In the PowerShell terminal window, run this:
mkdir $HOME\.kube
  1. Copy your kubeconfig file (see Prerequisites above) to the file path and filename $HOME\.kube\config. Make sure the file does not have a filename extension such as .txt. The kubeconfig file should be named simply config.

Tips:

 

    1. Get a kubeconfig file from the Kubernetes cluster administrator who maintains the Kubernetes cluster that SAS Viya is deployed into.
    2. If you want to give it another name, or put it in another directory, you can define an environment variable called KUBECONFIG and give it the value of the path to the kubeconfig file you want to use, and then kubectl will use that config file. This is useful if you have more than one kubeconfig file and wish to switch between them. You can specify a kubeconfig file on the kubectl command line (kubectl --kubeconfig path), but if becomes a bit cumbersome and clutters up the command, so I prefer not to do that.
  1. Run this from the PowerShell terminal prompt to view the contents of the kubeconfig (config) file to verify it is in the expected location:
type $HOME\.kube\config

Here is a screenshot showing the content of a config file (with the certificate data obscured). Yours should resemble this, though the server, cluster, user and context names will differ:

 

ds_6_kubeconfig-file.png

 

 

  1. Validate that you now have access to your Kubernetes cluster using kubectl and your kubeconfig file. Run this from any directory in the PowerShell command window (it should also work from a Windows command prompt):
kubectl get ns

Expected output is a list of the namespaces in your Kubernetes cluster, e.g. here in PowerShell, but the output is almost identical from a command prompt. We will switch to using a command prompt later, when we use the sas-viya CLI:

PS C:\Users\student> kubectl get ns
NAME              STATUS   AGE
argo              Active   10d
cert-manager      Active   10d
default           Active   10d
gelcorp           Active   10d
kube-node-lease   Active   10d
kube-public       Active   10d
kube-system       Active   10d
nfs               Active   10d
nginx             Active   10d
v4mlog            Active   10d
v4mmon            Active   10d
PS C:\Users\student>

One of the Kubernetes namespaces should be the namespace where SAS Viya is deployed – in the example above, that namespace is gelcorp.

 

Note: It is useful to be able to connect to more than one SAS Viya deployment. So, I prefer to include the namespace name in any configuration variables or file names which refer to that SAS Viya deployment. Therefore, from here on in this guide, wherever you see the string gelcorp in a variable or file name, you should substitute the name of your SAS Viya namespace into that variable or filename, instead of gelcorp.

 

Certificates file

 
In this step, we copy a trustedcerts.pem certificates file from the SAS Logon service in your SAS Viya deployment to allow the SAS Viya CLI to trust the TLS certificates that SAS Viya will present to it. If you have not enabled TLS for communication between your SAS Viya deployment and external clients (browsers and the CLI), and you access SAS Viya using http, not https, you may be able to skip this step.

  1. Create a directory for the certificates. In the PowerShell terminal window, run this:
mkdir $HOME\.certs
  1. Optional: See the name of your SAS Viya deployment's sas-logon-app pod. Remember to replace gelcorp in the command which follows with the name of your SAS Viya deployment’s namespace. In the PowerShell terminal window, run this:
kubectl -n gelcorp get pod -l 'app=sas-logon-app'
  1. Store the sas-logon-app pod name in a variable:
$SAS_LOGON_APP_POD_NAME=$(kubectl -n gelcorp get pod -l 'app=sas-logon-app' | select-string sas-logon-app | Foreach-Object { $_.ToString() -split '\s+'} | select-object -first 1)
echo $SAS_LOGON_APP_POD_NAME
  1. Copy the trustedcerts.pem file from the sas-logon-app container in the sas-logon-app pod to a file named gelcorp_trustedcerts.pem in the .certs directory you just created. Run this in PowerShell, substituting all occurrences of gelcorp for your namespace name:
Push-Location
Set-Location Env:
cd $HOME
kubectl -n gelcorp cp $SAS_LOGON_APP_POD_NAME":security/trustedcerts.pem" .certs\gelcorp_trustedcerts.pem -c sas-logon-app
Pop-Location

Note: The code above can surely be improved. I had trouble concatenating the destination path $HOME\.certs\gelcorp_trustedcerts.pem in the command, so I had to change directory instead, and for neatness change back afterwards. Let me know if you see a neater way to do that!

  1. Verify you got the certs file, again substituting gelcorp for your namespace name:
type $HOME\.certs\gelcorp_trustedcerts.pem

Expected results – LOTS of output!

 

 

Define SAS Viya CLI profiles

 
  1. Optional: see details of the ingress defined for your Viya deployment’s sas-logon-app service. Remember to replace gelcorp in the command which follows with the name of your SAS Viya deployment’s namespace. In the PowerShell terminal window, run this:
kubectl -n gelcorp get ing | findstr sas-logon-app

Expected output is something resembling this, showing in this example that the ingress hostname is gelcorp.pdcesx03038.race.sas.com:

PS C:\Users\student> kubectl -n gelcorp get ing | findstr sas-logon-app
sas-logon-app nginx gelcorp.pdcesx03038.race.sas.com,*.gelcorp.pdcesx03038.race.sas.com 10.43.17.23 80, 443 10d
  1. Get the ingress URL and store it in a shell variable. In the PowerShell terminal window, run this – you might need to modify it to fit the string returned from kubectl get ing on your environment, and again, remember to replace both occurrences of gelcorp in the command which follows with the name of your SAS Viya deployment’s namespace:
$INGRESS_URL=$(kubectl -n gelcorp get ing | select-string sas-logon-app | Foreach-Object { $_.ToString() -split '\s+'} | select-string gelcorp |%{$_ -split ','} | select-object -first 1)
echo $INGRESS_URL
  1. In your PowerShell terminal window, create a default sas-viya CLI profile which will be used if you don't specify which profile to use when calling the sas-viya executable, and one for your SAS Viya namespace, e.g. mine is called gelcorp, but you should name yours for your SAS Viya namespace. Specify http or https as appropriate for the endpoint:
sas-viya.exe --profile Default profile set-endpoint https://$INGRESS_URL
sas-viya.exe --profile Default profile toggle-color off
sas-viya.exe --profile Default profile set-output fulljson

sas-viya.exe --profile gelcorp profile set-endpoint https://$INGRESS_URL
sas-viya.exe --profile gelcorp profile toggle-color off
sas-viya.exe --profile gelcorp profile set-output fulljson

Validate that sas-viya CLI can access your SAS Viya deployment

 
Now you have everything you need to access a SAS Viya deployment using the SAS Viya CLI. Let’s validate that we can, using the Windows Command Prompt.

 

Note: This step uses Windows Command Prompt, not PowerShell!
  1. Open a Windows Command Prompt terminal window. It may be convenient to pin it to the Windows Task Bar or Start Menu.
  2. In your Windows Command Prompt set environment variables for using the sas-viya CLI. As before, substitute the name of your SAS Viya deployment's namespace for gelcorp:
set current_namespace=gelcorp
set SAS_CLI_PROFILE=%current_namespace%
set SSL_CERT_FILE=%USERPROFILE%\.certs\%current_namespace%_trustedcerts.pem
set REQUESTS_CA_BUNDLE=%SSL_CERT_FILE%
  1. Run this (from any directory) in your Windows Command Prompt to log in to your SAS Viya deployment from the SAS Viya CLI. Provide the username and password of the account you will use to login to SAS Viya (see Prerequisites above), in place of username geladm password lnxsas in the example below:
sas-viya auth login -u geladm -p lnxsas

Expected output is something like this:

C:\Users\student>sas-viya auth login -u geladm -p lnxsas
Enter credentials for https://gelcorp.pdcesx03038.race.sas.com:
Login succeeded. Token saved.

C:\Users\student>
  1. You should now be able to run sas-viya commands to do anything that username is authorized to do. Try using the SAS Viya CLI to get information about the SAS Administrators group:
sas-viya identities list-groups --id SASAdministrators

Expected output is something like this (with some lines omitted):

C:\Users\student>sas-viya identities list-groups --id SASAdministrators
{
    "items": [
        {
            "creationTimeStamp": "2023-07-13T08:15:30.881Z",
            "description": "Provides assumable access throughout the general authorization system.",
            "id": "SASAdministrators",
            "links": [
               --- some lines omitted---
            ],
            "modifiedTimeStamp": "2023-07-13T08:15:30.881Z",
            "name": "SAS Administrators",
            "providerId": "local",
            "state": "active",
            "type": "group",
            "version": 1
        }
    ]
}
If you see JSON output similar to that above, your SAS Viya CLI has successfully authenticated and run a command against your SAS Viya deployment. Let’s try a few more examples.

 

Use the SAS Viya CLI from a Windows command prompt

  Note: This step uses Windows Command Prompt, not PowerShell!

 

SAS Viya CLI Examples

 
There are lots of other videos and blog posts describing use of the sas-viya CLI. A search here, or using your favorite web search engine will produce many results, and I'd encourage you to explore topics, tasks and plugins that seem interesting to you. It is a fantastic set of tools! But here, I'll pick some examples that seem interesting to me - and I hope to you.

 

The results of each of the following examples is from one of the GEL workshop environments. Obviously the values returned will vary between SAS Viya deployments, so expect your results to differ from mine, and go explore what you can do!

 

See the usage help text for the sas-viya compute contexts command

All sas-viya plug-ins, including the compute plug-in are designed to be self-documenting. Add a -h at the end of any partial command to see what sub-commands, command options and arguments it can take. This is a great way to discover what they can do.
  1. In the command prompt, run this to see usage for the sas-viya compute contexts command:
sas-viya compute contexts -h

Expected output (other versions of the plugin may offer different options and arguments to these):

NAME:
   sas-compute-cli contexts - Manages the compute contexts.

USAGE:
   sas-compute-cli contexts command [command options] [arguments...]

VERSION:
   1.37.8

COMMANDS:
   create                       Creates a compute context.
   delete, del                  Deletes a compute context by name, ID, or ordinal.
   generate-template, gen       Generates a template to create a compute context.
   help, h                      Shows a list of commands or help for one command.
   list                         Lists the compute contexts' names and IDs.
   show                         Shows a compute context by name, ID, or ordinal.
   show-template, show-t        Shows a template that is used to create a compute context.
   validate, val                Validates the compute context session.

OPTIONS:
   --help, -h   Shows help.

List compute contexts

  1. In the command prompt, run this to list compute contexts currently defined in your SAS Viya deployment (and that your current user is authorized to see):
sas-viya compute contexts list

Expected output (your compute contexts may differ to these, and the IDs will be different):

1. SAS Studio compute context c4eeed2e-2c5e-48ee-ac69-9c82889a4081
2. SAS Job Execution compute context 14f5cc90-bd7c-4306-bee2-830cd6c34bee
3. CAS Formats service compute context 4c786325-25d0-46e6-81d7-038d3bc9efa7
4. CAS Management service compute context 989ba5c6-2ede-4011-90e2-d69110aa2d6d
5. SAS Model Manager compute context d731a2dd-249b-4301-9296-31ef8364049e
6. Import 9 service compute context 695b9e48-c0cf-4be5-bd4b-be1e8d3c5cb4
7. Natural Language Conversations service compute context f23a7bc4-78b4-48a8-bfab-f6ee184edc97
8. Data Mining compute context f3ec8041-bf8b-46a0-9805-2ab9c1f50a76
9. SAS Backup job compute context e436717f-cd5c-43fe-9231-c2d805692b62

List the details of the SAS Studio Compute Context

  1. In the command prompt, run this to view details of the SAS Studio Compute Context. You can indicate which compute context you want to see by ordinal number, name or id - here I chose to identify it by name:
sas-viya compute contexts show --name "SAS Studio compute context"

Expected output (some lines omitted for brevity):

{
    "createdBy": "sas.studio",
    "creationTimeStamp": "2023-07-13T08:18:09.70045Z",
    "description": "Compute context to be used by the SAS Studio service",
    "environment": {},
    "id": "c4eeed2e-2c5e-48ee-ac69-9c82889a4081",
    "launchContext": {
        "contextName": "SAS Studio launcher context"
    },
    "launchType": "service",
    "links": [
        --- some lines omitted ---
    ],
    "modifiedBy": "sas.studio",
    "modifiedTimeStamp": "2023-07-13T08:18:09.70045Z",
    "name": "SAS Studio compute context",
    "version": 4
}
If your objective was only to set up the SAS Viya CLI, and not pyviyatools, you are finished, and I hope this process has been useful.

 

No doubt this guide could be improved. If you see areas you think are overcomplicated, wrong or unnecessary, or if you have questions about why I chose a particular command or installation method, I would love to hear from you. Please leave a comment below or get in touch.

 

If you want to continue to set up pyviyatools, look no further than part 2 Install and use the pyviyatools on Windows. 

 

My thanks to my colleagues Gerry Nelson and Allan Tham for their help in discussing and refining some of the things I included in this guide.

 

See you next time!

 

Find more articles from SAS Global Enablement and Learning here.

Comments

Tried this approach with Linux OS and works perfectly for me

Version history
Last update:
‎07-26-2023 01:52 PM
Updated by:
Contributors

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!

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