Skip to main content Link Menu Expand (external link) Document Search Copy Copied

Hands-on 03: SAS Viya Workbench

As of 2024, SAS Viya Workbench is the latest offering from SAS. SAS Viya Workbench is a flexible, secure, and scalable on-demand cloud computing environment built for data science. It empowers developers, modelers, and programmers with latest high-performance analytics from SAS, seamlessly integrating both SAS and open-source code in an easy to use environment with a choice of programming interfaces such as Jupyter Notebook, Jupyter Lab or VS Code, with more exciting options to come.

Connect to SAS Viya Workbench

In the previous exercises you were using a dedicated instance of SAS Viya running locally on your machine. SAS Viya Workbench is a hosted offering, so you will all connect to a shared central environment via browser, each one using a dedicated user ID.

  1. Navigate to https://explore-viya-workbench.sas.com/. A Sign in dialog appears. Enter the student ID assigned to you, it should be similar to studentN@sasinnovate.com, where N is the number of your seat. As you confirm the username, you will be prompted for the password. Enter Metadata0.

  2. The first time you open SAS Viya Workbench, the Welcome window will open. Close it to go to the SAS Viya Workbench homepage.

    Note: For some students this Welcome window might not appear. Do not worry, it’s because we already closed it for you.

  3. We will explore the Home Page later. For now, click Open Visual Studio Code to get started immediately with your first workbench.

  4. A new browser tab will open. It will briefly inform that a new workbench is being started for you, with a SAS compute engine allocated in the background.

Experience SAS in a VS Code workbench

For SAS programmers, Workbench provides the SAS code you are familiar with, as well as new high performance SAS Viya analytics for use in either SAS or Python.

  1. As soon as your workbench is ready, you are greeted by the web edition of VS Code. Close the Welcome page and leave the defaults as they are. On the left side, you can see the familiar VS Code navigation bar. In the Explorer section, you can find the storage allocated to your workbench under the name ‘MYFOLDER,’ which provides some demo files and folders.

  2. Create an empty file by selecting the menu button -> File -> New Text File.

  3. Click on Select a language, then search for and select SAS.

  4. Now you can quickly start coding in SAS. In this exercise we’ll use simple CONTENTS, PRINT, FREQ and MEANS procedures to quickly explore the cars table from the SASHELP library. Again, using SAS procedures which are very familiar to SAS programming community. Copy and paste the following code:

    /* SAS Innovate 2024 */
    ods html5 style=Illuminate;
    ods select Variables;
    proc contents data=sashelp.cars;
    run;
    
    proc print data=sashelp.cars(obs=5);
    run;
    
    proc freq data=sashelp.cars order=freq;
        tables Make Origin EngineSize / plots=freq;
    run;
    
    proc means data=sashelp.cars mean;
        class Make;
        var MPG_City MPG_Highway;
    run;
    
  5. To run the code, you can select the familiar running man icon at the top right, or press F3. The results open in a new tab. Here you can quickly scroll through and see the output. From the table metadata, to the frequency analysis and plots, to the descriptive statistics. On the bottom, you can see the SAS log.

  6. If you want to view your available SAS libraries in VSCode, select the SAS extension icon. Here, you can find see some of the familiar libraries like MAPS, SASHELP, SASUSER, and WORK.

Explore SAS Viya Workbench main interface

  1. Close the VS Code browser tab, so that you are sent back to the SAS Viya Workbench home page. Explore the interface: the left navigation bar enables you to access your available Workbenches, Storage options, and Activity Log. The central pane lists all the workbenches that you have allocated in this environment. As you can see, even after you closed the VS Code browser tab, your workbench session is still active.

  2. Click Open Visual Studio Code. A new browser tab will open, and you will find your VS Code window as you left it, with the SAS code you just entered. Close the VS Code browser tab again, to go back to the SAS Viya Workbench home page.

  3. In the central pane select the 3 dots button -> Settings to explore the configuration settings available in your environment.

    Notice how you can rename your workbench, spin up a new compute engine with more - or less - resources, attach a different storage. Based on your environment and what your site administrator has configured, you might have the possibility to choose specific performance levels, even the ability to use a GPU.

    For now, simply select Cancel to close the dialog.

Experience Python in a Jupiter Lab workbench

  1. Let’s explore a different client interface. In the workbench panel, click the Stop button to stop the VS Code workbench. When it is stopped, select the down arrow next to the Open Visual Studio Code button. You have the option to open Jupyter Notebook, Jupyter Lab or VS Code. Select Open Jupiter Lab.

  2. A new workbench will be started in the background. It should be ready in a few second. A new browser tab will open and display the Jupiter Lab interface:

  3. Let’s open a demo Python Notebook that shows how to leverage SAS Viya Workbench analytical procedures in Python. The Files Browser panel should be already open in the /workspaces/myfolder folder. Navigate into the python folder and double click on the forest_digits_sasviya.ipynb file to open it in the main panel (you may have to resize the panels to see the full filenames).

  4. Select the Run -> Run All Cells menu.

  5. In less than a minute the notebook should finish running. Scrolling up to cells [1], [2], and others, you can see that it’s using regular Python packages such as sklearn and matplotlib. Then, in cell [7] the sasviya package is used to provide the ForestClassifier algorithm to build our model. Finally, sklearn is used again to gather and print information on the model such as the confusion matrix and the classification report.

    Notice how you, as a Python coder, do not have to learn and use anything that is SAS-centric, such as connection parameters, SAS data formats, pre/post SAS code, and so on. Just import and use the sasviya package, as you do with any other one.

This is the end of the exercise. Let’s be good citizens and save computing resources: close the Jupiter lab window, then, in the SAS Viya Workbench home page, click Stop, click the person icon at the top right, and click Sign out.


Back to top

Copyright © SAS Institute Inc. All Rights Reserved.