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!
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.
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.
Then, choose the SAS 9.4 (remote – IOM) connection. Press Enter.
Now, enter the name of the SAS 9 server. Press Enter.
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.
Then, enter your SAS server username. Press Enter.
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.
The name of your connection appears on the bottom status bar.
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.
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.
Just like in SAS Enterprise Guide or SAS Studio, select the running man icon 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.
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.
Now, let’s highlight and run the PROC PRINT step alone. Notice a second results tab appears.
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.
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.
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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.