BookmarkSubscribeRSS Feed

SAS Extension for Visual Studio Code

Started ‎06-30-2022 by
Modified ‎07-17-2023 by
Views 28,130

TL;DR

SAS has officially released a VS Code SAS programming code extension. The extension is available on SAS’ Visual Studio Marketplace, and we’ve also created the sas-vscode-extension repository on sassoftware GitHub. The extension is available for use on SAS Viya and also works with specific configurations of SAS 9.

 

See this video introduction from @DavidHD to get started.

 

See also David's update about the most recent additional features.

VS Code SAS Extension Introduction

In 2019 a survey on Stack Overflow listed VS Code as the IDE of choice for 50% of the developers surveyed. That number jumped to 71% in 2021. Moral of the story: VS Code is popular in the developer community and is still growing in adoption. Rather than asking developers to log into, and code in, the SAS UI, we’ve developed the VS Code SAS Extension. The tool offers users an integration point for adding SAS programs and code into their work, without having to switch applications. The tool also offers the ability to connect directly to SAS Viya and run code.

 

Repeat for those who skipped TL;DR: The extension is available on SAS’ Visual Studio Marketplace, and we’ve also created the sas-vscode-extension repository on sassoftware GitHub. The extension is available for use on SAS Viya only.

 

Features

The extension offers the following features.

SAS Syntax Highlighting Color Themes Code Completion
Pop-up Syntax Help Snippets Code Folding and Code Outline
Configuring the SAS Extension Running SAS Code VS Code for the web compatible
VS Code Notebooks Data Viewer  

 

The list above is not exhaustive and we're just at the beginning. We plan on adding more features over time. I will not go through the specific features in this article. Rather, I’ll offer some background on why SAS created the tool, how it can benefit users, run through a short use case, and challenge you to be creative in using the extension.

 

Who are we trying to reach?

The extension is open for use by anyone using VS Code; however, there is certainly a user base that would be more apt to adopt it. We’re a data-driven company. Numbers don’t lie. Based on the Stack Overflow survey results, it’s clear developers do their work in VS Code. We need to meet these users where they are. Consider the scenario below and see how the extension benefits developers.

 

The developer using VS Code

If during the day you write Python, then some JavaScript, and then some SAS, and VS Code is your favorite place to be… now you can write your SAS code there too. Our goal is to meet your SAS programming needs by supporting the number one code editor in the industry today. Our new VS Code extension for SAS is lightweight, runs anywhere, and allows you to integrate SAS and other languages.

 

Let’s also consider other potential users.

 

The SAS Studio user

We’re not suggesting SAS programmers alter what they do in SAS Studio, in any way. The VS Code extension offers an alternative, if the need arises, to be flexible with a new integration point.

 

What about other users?

Additionally, students, companies that support the use of VS Code in their tech stack, and Microsoft’s Azure DevOps customer base will have the opportunity to make use of the SAS extension.

 

Project development and support

While the initial contribution of core functionality is by SAS R&D, we expect and encourage continued contributions by SAS developers, partners, and consultants. In fact, we’ve already seen issues logged and conversations occur in the Marketplace and on GitHub.

 

SAS has a commitment to support the community contribution effort through code reviews and assistance with critical bugs. We also expect this to be a popular topic in the SAS Support Community. A conversation on this subject in the Developers Community has over 6k views and comments from several users wanting to contribute.

 

Install, configure, and feature use

 

Video format

In the following video, I cover extension installation, configuration, and highlight multiple features.

 

 

 

Text format

Let's take a look at installation and functionality using this simple use case.

  1. install the extension
  2. add SAS Code to a programming window in VS Code
  3. configure connection to SAS Viya instance
  4. run the code and verify the results

 

Install the extension

Two ways to accomplish this:

  1. Go to the SAS page on Visual Studio Marketplace and click Install.
    • This should open VS Code and install the extension for you.
  2. Open VS Code, navigate to Extensions and enter SAS in the filter.
    • Make sure to find/install the extension with the description Official SAS Language Extension for VS Code.

 

Configure the SAS theme

This setting enables things like SAS programming color coding, type ahead, the 'SAS running man' icon, and other SAS-specific features.

  1. Navigate to File-> Preferences, Color Theme
  2. Choose one of three SAS themes: SAS Light, SAS Dark, or SAS High Contrast

 

Enter SAS code

  1. Open a new programming window by selecting File-> New Text File, click Select a language, and choose SAS from the list.
  2. Enter SAS code (you can use the following test code or use your own).
data race;
    pr =probnorm(-15/sqrt(325));
run;
proc print data=race;
    var pr;
run;

 

Establish connection

For more information about the authentication process, please see the blog post Authentication to SAS Viya: a couple of approaches.

 

You can create a Profile with connection information to SAS Viya. You have the ability to create multiple profiles to connect to different SAS Viya environments. Profile configuration depends on your SAS Viya version. 

 

Connecting to SAS Viya, release 2022.11 and later

Connections to SAS Viya use an authorization code and the pre-loaded vscode client id.

  1. Press F1 to kick off the 'SAS: Add New Connection Profile' wizard
  2. Enter a profile name
  3. Provide the SAS Viya url, e.g., https://sasserver.sas.com
  4. When prompted to enter client id, PRESS Enter, do not provide a client id.

 

Connecting to SAS Viya, prior to release 2022.11 (including Viya 3.5)

Connections to SAS Viya use an authorization code and a client id created by a SAS Admin

  1. Press F1 to kick off the 'SAS: Add New Connection Profile' wizard
  2. Enter a profile name
  3. Provide the SAS Viya url, e.g., https://sasserver.sas.com
  4. When prompted to enter client id, enter a valid client id (see documentation for client registration steps)
  5. Enter a client secret

 

More information on profile creation is in the preceding blog post link and on GitHub. If you hit connection issues, refer to the FAQ on GitHub.

 

Run code

The extension uses the current profile to connect to SAS Viya. On the initial connection to SAS in a VS Code session follow these steps:

  1. Click on the SAS running man in the upper-right-hand corner of the code window.
  2. A SAS login screen appears
  3. Log in using your SAS credentials
  4. If prompted, authorize access for all scopes
  5. Copy the generated authorization code
  6. Paste the authorization code in VS Code
  7. Results should be displayed in the Results tab.

See the Running SAS Code section of the README for more details.

 

Note: subsequent calls in the same VS Code session will connect directly to SAS Viya. You do not need to repeat the authorization code steps.

 

Use cases needed

Want to become a star? Ready to impress everyone? Here’s where you can help. You'll hear plenty from SAS about the new VS Code extension; however, oftentimes our users come up with the best ideas for use of our software and tools. If you have a use case that’s more interesting than what’s outlined above (a simple code example, only using SAS), we’d love to hear about and feature it.

 

Finally

Is this project complete? Absolutely not. We're adding additional functionality and making improvements based on user feedback. We've also processed multiple pull requests on GitHub incorporating changes from the field. We want to continue providing proper functionality, responding to user concerns, and facilitating the use of our new extension. Try it out and tell us what you think.

Comments

This is Great! Any upcoming plans to support Web Job Execution Server code, parameters and associated HTML pages? Would really be useful to be able have true source code control over JES jobs and web pages.

Hi @eneidam,

Thanks for your inquiry. To my knowledge nothing is in the works, but I really like your idea. I'd suggest posting this as in Issue in the GitHub repository. That's the best place to log feature requests.

Thank you @joeFurbee  !  This is a great tool and the video demo is also very engaging in order to adopt it. I am not familiar with VsCode, this might change quite soon 😉 

I cannot connect at the moment with a Viya 4 installation, I would like to know wich API type and protocol does the extension use actually. I guess this is RESTful / http(s) but I need to be sure for a network route opening.  Behind the scenes, is this the Compute services being consumed or another one ? 

 

https://support.sas.com/content/dam/SAS/support/en/sas-global-forum-proceedings/2018/2083-2018.pdf

 

I saw on the Github page a request for having SAS 9 (local Foundation AND/OR remote IOM) also as an endpoint to the extension. I would be very interested with this feature since this would enable a side by side exploitation { SAS 9 } |  { Viya } during migrations from SAS 9 to Viya, thus streamlining manual unit testing for instance. 

Hi @ronan,

Answers to your questions:

The  the extension is connecting with REST API over http(s) to the Viya compute service.

 

At this time the extension is for SAS Viya only. We are exploring the possibility of further feature development for SAS 9 compatibility. Stay tuned.

 

 

 

Thank you, @joeFurbee , that's clear.

Hi is the extension supported in RedHat  OS ? We are having troubles in installing it on VS Code running on Linux RedHat.

 

Thanks

Hi @mbertol4  - I suggest you post the question as a GitHub issue and the team can respond.

Submitted in GitHub as suggested.

Thanks

Hi, Great! Is there also a possibility to access the NFS (Network File System) in VS CODE as in SAS Studio? I have organized my Code and other files (excel files e.g.) in NFS folder (using "classic" statements like %include and classic access of excel or textfiles.  And I want to save and run .sas Files stored in NFS directly from VS Code. So not to use only the SAS (Metadata) Content.

 

@AThomalla When using VS Code to run SAS programs, the programs are run on your SAS environment. So whatever environment you connect with must have access to the files you reference with %include or filename statements. If all of your files are "local" to your desktop, but your SAS session is remote -- then each flle that you need must be uploaded to that remote environment before you can reference it.

@ChrisHemedinger 

Thanks for your reply. Yes, I can access my files running code on the server, but my question is, if I can access these files (open, edit, save as in SAS Studio) directly from VS Code (so organize my code files within VS CODE). My intention is also a bit: if some future AI Copilot Extensions (github copilot, openai) will be able to create code for you based on own nomenclatura of dataset filenames and attribute names AND your existing code/project, it will be probably usefull that VS CODE hast access to these files. And for me currently it is not a solution to move my code to SAS (Metadata) Content because then existing "classic" programms and methods are not working without migration (e.g. I use alread proc python and cool methods produced with help of chatGPT which use usual file system (excel, text, code files)).

@AThomalla I think I understand. I don't know what the future holds for tools like Copilot being able to help you craft code that is specific to your data files and their metadata. That's granting the tool a lot of access to your SAS-controlled data and may be problematic from a policy standpoint (it certainly would be a concern in our workplace).

 

But lots of people are like you in that they manage their SAS files in the file system, not in metadata or content server. VS Code is a client to SAS (like EG is or SAS Studio), and so can only do so much to manage your local files in concert with their meaning/semantics in your remote SAS environment.

@ChrisHemedinger thanks for the update. As VS CODE is a client like SAS STUDIO I just wonder, why access the NFS Files is not provided as within SAS Studio as well. As mentioined, existing SAS Applications which base on SAS Files managed in the file system are not directly compatible with sas files or files in general stored in metadata. Would be nice, if SAS would enable managing the NFS files in VS Code same as in SAS Studio...

 

Regarding the sucerity concern using extensions like copilot its clear... But in my view its the future for "smart" solution building. And one should be aware of it when planning future architectures and development methods within the dev teams.

 

Currently the quality of chat GPT output with Python is amazing in my opinion. Imaging one would combine the already exisiting features with (secure) access to own data: that will be funny :-).

Thanks!

@AThomalla My statement that VS Code is a client like SAS Studio is sort of misleading, since VS Code is installed locally and SAS Studio is on a remote server (on network with your NFS share) close to your SAS session. If where you're running VS Code and where you run SAS are sharing the same file system/network, then these references could work. However, that's often not the case.

Just started using this with my SAS 9.4 local PC Windows install, and first let me say, it looks awesome! I'm trying to get my whole dept to consider it as alternative to native PC 9.4 editor. I have two questions, though:

1) How do you get the LIBRARIES pane - as shown at 5:13 in the video. Is LIBRARIES pane only visible if you connect to SAS Viya? Is it visible for those of us using SAS 9.4 on our local Windows PC, with no SAS Viya server? I see the Libraries header, but when I expand it, it contains no library names, not even SASHELP.

2) Even though he is using SAS Dark theme, at 9:40 in the video, his SAS output shows with white background - similar to how it appears in SAS Enterprise Guide. But when I use SAS Dark theme, SAS output is also dark theme (dark background, etc.). How did he get output to appear with light background?

@bnawrocki Libraries/data set viewing is not yet supported for local connections but it is being worked on!

 

The output theme is tied to ODS styles. The extension will try to match an ODS style to your editor theme, but of course it's not 1-to-1 and you can override by adjusting your ODS HTML5 statement to include the style= value of your choice.

@ChrisHemedinger - thanks for the quick response.

After reading your comments, I looked at SAS Enterprise Guide HTML option (via Tools --> Options-->HTML) and saw it uses HTMLBlue style.

I was able to reproduce SAS EG's HTML style by adding this code to top of my SAS code in Visual Studio Code:

   ods html5 style=htmlblue;
 
As a side note: I first saw Visual Studio Code and its SAS extension at SESUG2023 in Charlotte in October, so yes, a regional SAS conference is worth attending!
Version history
Last update:
‎07-17-2023 02:37 PM
Updated by:

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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