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.
In Part 1 of this guide, we will cover:
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.
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:
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 |
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
Without such a tool, you must either:
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.
Note: This step cannot currently be automated without software which I think is too expensive or complex to recommend for this use case alone.
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.
cd C:\ViyaHome\CLI .\sas-viya plugins install --repo SAS all
[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.
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.
Get-ExecutionPolicy
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
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.
.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.
choco install curl -y
mkdir "C:\Program Files\kubectl"
cd "C:\Program Files\kubectl" curl.exe -LO https://dl.k8s.io/release/v1.27.2/bin/windows/amd64/kubectl.exe
& "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>
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.
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>
mkdir $HOME\.kube
$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:
kubectl --kubeconfig path
), but if becomes a bit cumbersome and clutters up the command, so I prefer not to do that.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:
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
.
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
.
mkdir $HOME\.certs
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'
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
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!
gelcorp
for your namespace name:type $HOME\.certs\gelcorp_trustedcerts.pem
Expected results – LOTS of output!
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
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
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
Note: This step uses Windows Command Prompt, not PowerShell!
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%
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>
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.
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!
-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.
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.
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
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.
Find more articles from SAS Global Enablement and Learning here.
Tried this approach with Linux OS and works perfectly for me
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!
Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning and boost your career prospects.