BookmarkSubscribeRSS Feed

Visual Studio Code with the SAS Extension for Analytics Pro Users (Part 2)

Started yesterday by
Modified yesterday by
Views 107

SAS Analytics Pro now offers greater flexibility in how and where you write your code. In addition to SAS Enterprise Guide, you can connect to SAS Analytics Pro directly from Visual Studio Code (VS Code) using the SAS Extension for VS Code. In this post, we’ll explore how to connect to SAS Analytics Pro in VS Code, run SAS programs and notebooks, identify and fix errors, and personalize your workspace layout. This builds on part 1 of the series, which introduced how to navigate the Visual Studio Code interface. Let's get started!

 

Connecting to SAS Analytics Pro

 

To establish a connection to SAS Analytics Pro in Visual Studio Code, Enter Ctrl + Shift + P to open the command line for VS code. This is the search bar at the top that lets you quickly run commands. Then type SAS: Add New Connection Profile and select it from the list.

 

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

 

Next, enter a connection name - I’ll use SAS Analytics Pro - and press Enter. The connection name can be anything you’d like.

 

02_ST_part21-1.png

 

Then, choose the SAS 9.4 (remote – IOM) connection. Press Enter.

 

03_ST_part23.png

 

Now, enter the name of the SAS 9 server. Press Enter.

 

04_ST_part24.png

 

Next enter the port number and press Enter. I am using the out of the box default port number 8591; however, users have control over what the port should be. Visit Using VS Code and Enterprise Guide with SAS Analytics Pro for more details.

 

05_ST_part26.png

 

Then, enter your SAS server username. Press Enter.

 

06_ST_part25.png

 

Next, navigate to the SAS Extension from the activity bar on the left, click Sign In, select the name of the SAS connection profile you just created, and enter the password to connect to your SAS Server.

 

Note: After selecting the SAS connection profile, you may need to click Sign In again before the password prompt appears.

 

07_ST_part27.png

 

08_ST_part28.png

 

09_ST_part29.png

 

The name of your connection appears on the bottom status bar.

 

10_ST_part211.png

 

Now you are connected to SAS Analytics Pro and ready to start programming!

 

From the SAS Extension view, you can access any files on your SAS Server and view your SAS libraries. Just like in SAS Studio or Enterprise guide, you can expand a library and double-click a table to view it. The table view shows the data along with an icon indicating each column type.

 

11_ST_part210-1024x723.png

 

 

Running a SAS Program

 

Let’s run a simple SAS program. Select File > New File… > SAS File or type SAS: New File... in the command prompt. The following code reads in the SASHELP.CARS table, calculates average miles per gallon, and prints a portion of the data along with a summary statistics table, although there are some errors.

 

daat mycars;
  set sashelp.cars;
  AvgMPG=mean(mpg_city, mpg_highway);
run;

title "Cars with Average MPG Over 35";

proc print data=mycars
  var make model type avgmpg;
  where AvgMPG > 35;
run;

title "Average MPG by Car Type";

proc means data=mycars average min max maxdec=1;
  var avgmpg;
  class type;
run;

title;

 

When you paste it in the code editor, notice the program is color coded for easy readability. In addition, Visual Studio Code gives suggestions as you type.

 

12_ST_part213.png

 

13_ST_part212.png

 

Just like in SAS Enterprise Guide or SAS Studio, select the running man icon Icon1_ST_part214.png to run the program.

 

Looking at the status bar at the bottom, we can see there are several errors and warnings related to the program. The OUTPUT tab in the bottom pane displays the log information, while the PROBLEMS tab lists the specific errors and warnings such as a misspelling of DATA, a missing semicolon, and an unrecognized keyword. Clicking on any error or warning takes you directly to the corresponding line of code.

 

14_ST_part215-1024x164.png

 

Let’s fix these errors and rerun the program with the following corrected code:

 

data mycars;
  set sashelp.cars;
  AvgMPG=mean(mpg_city, mpg_highway);
run;

title "Cars with Average MPG Over 35";

proc print data=mycars;
  var make model type avgmpg;
  where AvgMPG > 35;
run;

title "Average MPG by Car Type";

proc means data=mycars mean min max maxdec=1;
  var avgmpg;
  class type;
run;

title;

 

The code runs with no errors or warnings, and we see a results tab appear.

 

15_ST_part217-1024x551.png

 

Now, let’s highlight and run the PROC PRINT step alone. Notice a second results tab appears.

 

16_ST_part218.png

 

Since Visual Studio Code is a generic framework where users may have multiple plugins running concurrently, the interface may not appear exactly how users are used to in a workspace owned by a single application. For example, by default, VS code creates a new tab every time a new set of results is created; however, you can change this setting from the SAS Extension page. Click the Extensions icon in the activity bar and select the SAS Extension. From the SAS Extension page, select the settings icon > Settings and check Reuse single panel to display results. You can also change the setting to not show the results side by side with the code, but as a separate tab instead.

 

17_ST_part220-1.png

 

 

Running SAS Notebooks

 

Users can also create modern SAS Notebooks which provide a more flexible and user-friendly way to work with SAS code.

 

SAS Notebooks support cells of type Markdown, SAS code, SQL code (using proc SQL syntax), and Python. You can run cells individually or run a complete notebook, and rearrange cells as needed. SAS Notebooks make it simple to combine documentation, code, and output into a single, interactive workspace.

 

18_ST_part2vid.gif

 

 

Conclusion

 

With SAS Analytics Pro in Visual Studio Code, you can run SAS programs, fix errors, and create interactive notebooks—all within a flexible, modern coding environment. The SAS Extension makes it easy to personalize your workspace, streamline your workflow, and get more done, faster.

 

For more information on SAS Analytics Pro and the Visual Studio Code SAS Extension, visit:

 

 

 

Find more articles from SAS Global Enablement and Learning here.

Contributors
Version history
Last update:
yesterday
Updated by:

SAS AI and Machine Learning Courses

The rapid growth of AI technologies is driving an AI skills gap and demand for AI talent. Ready to grow your AI literacy? SAS offers free ways to get started for beginners, business leaders, and analytics professionals of all skill levels. Your future self will thank you.

Get started

Article Labels
Article Tags