BookmarkSubscribeRSS Feed

VS Code Notebooks to SAS Studio Flows: the Easy Guide

Started ‎06-05-2024 by
Modified ‎06-05-2024 by
Views 744

The SAS extension for Visual Studio Code supports a special file type called “SAS Notebooks.” These are just like Python notebooks that you might have used in Jupyter or other environments. Notebooks allow you to mix code with documentation and results, encapsulating a work product that is easy to understand and demonstrate. What if you want to use SAS Studio to work with SAS notebooks as well? Read on to find out how!

 

I was privileged to teach a Hands-on Workshop at SAS Innovate in Las Vegas, Nevada this year. Titled “Interacting with SAS® Viya® Using SAS® Enterprise Guide® and Other Clients”, the session included an exercise dedicated to exploring the capabilities of  the SAS Extension for Visual Studio Code. One of these functionalities is the support for SAS Notebooks, which, just like Python notebooks that you might have used in Jupyter or other environments, allow you to mix code with documentation and results in an interactive online page. SAS Notebooks can integrate SAS, SQL, Python code and inline documentation in a seamless execution environment.

 

01_ER_20240515_01_Notebook.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.

 

While I was demonstrating this capability, one of the attendees asked “I often work on the same SAS programs both in VSCode and SAS Studio. Can I open a SAS notebook with SAS Studio as well?”. I’m glad they asked: I was just going to show how to close the circle from VSCode to SAS Studio, so my answer was a cryptical “Well, no, but almost yes”. What does that mean?

 

While at the moment you cannot use SAS Studio to directly open a “.sasnb” file (the format of SAS notebooks), it’s really easy to export a SAS notebook from VSCode as a “.flw” file (the format of SAS flows). Every cell in the SAS notebook becomes a node in the SAS Studio flow. SAS Studio can then open the file and let you work with the flow. Voila'.

 

Since this is a file conversion, changes made in the flow would need to be synched back to the notebook, but that is beyond the scope of this post. Always use good version management processes to synch such changes.

 

Step by step

 

Here is a guided step-by-step guide directly taken from the SAS Innovate session that shows you how to do it.

 

  1. After creating a SAS notebook in Visual Studio Code, save it by pressing CTRL+S. In this example, it is saved under “My Folder” with the name "Innovate24.sasnb".
  2. In the explorer pane, locate the file by expanding "My Folder", then right click on the "Innovate24.sasnb" file and select "Convert to Flow..." (this is a custom action that the SAS Extension to VS Code adds to the right-click context menu).

 

02_ER_20240515_02_Convert2Flow.png

 

  1. Press "Enter" to accept the default filename. VS Code will save the notebook as a SAS Studio flow, located in the same folder as the original file.
  2. Open the browser and sign into SAS Studio.
  3. In SAS Studio explorer pane, navigate to "Folder Shortcuts" > "Shortcut to My Folder" and double-click on the "Innovate24.flw" file to open it.

 

03_ER_20240515_03_OpenFlow.png

 

  1. The SAS Studio flow that is automatically generated by VS Code includes each cell in a dedicated swimlane to preserve the sequential execution nature of notebooks, both visually and in the generated code:

 

04_ER_20240515_04_SASStudioLanes.png

 

  1. You can verify the code in each node. As an example, select the Python Program node in SAS Studio to look at the code:

 

05_ER_20240515_05_PythonFlow.png

 

you should recognize the same code entered in VS Code in the original notebook:

 

06_ER_20240515_06_PythonNotebook.png

 

  1. Now that the flow is open in SAS Studio, you can submit it using the “Run” button to get the same results as the original notebook.

 

Conclusion

 

One of the objectives I had with this SAS Innovate session was to show how you can leverage your knowledge of a SAS client to jump into a different one, without having to re-learn how to use it from scratch. This can open the doors to benefiting from additional capabilities. As an example, SAS notebooks are inherently interactive and cannot be scheduled or submitted in batch from VS Code. Once you transform a notebook into a SAS Studio flow, that becomes possible:

 

07_ER_20240515_07_Schedule.png

 

If you want to see another example of how to use VS Code, including this integration with SAS Studio, see Ryan King’s post Using The SAS VS Code Extension to Check Prime Distribution.

 

 

Find more articles from SAS Global Enablement and Learning here.

Version history
Last update:
‎06-05-2024 04:48 PM
Updated by:
Contributors

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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