- R runtime: Install from CRAN.
- SAS access (for execution): SAS 9 or SAS Viya. Without a SAS server you still get syntax highlighting and linting for SAS.
- GitHub Copilot subscription.
- In VS Code, go to the Extensions view (
Ctrl+Shift+XorCMD+Shift+Xor find and "Extensions" icon on the left of your screen), and type SAS.
Select SAS: (by SAS Institute) – The official language extension for running SAS code and viewing datasets.
Install extension. - Open Command Palette: ( either
F1orShift+CMD+P) or using menu:View -> Command Palette; - Type: SAS: Add New Connection Profile
- Profile Type: Choose SAS Viya or **SAS 9.4 ** I chose "localhost", but depending on your installation you might need to select a different option.
- Once installed, you should see a "Running Man" icon in the opt right to execute your code. You should also see a SAS logo on the left-side of your VS Code window. Depending on your SAS installation type, you may need to sigh-in next time you open a VS Code.
- In VS Code, go to the Extensions view (
Ctrl+Shift+XorCMD+Shift+Xor find and "Extensions" icon on the left of your screen), and type "R" (make sure you use quotes around R) : Select R: (by REditorSupport) – Provides syntax highlighting, linting, and package management. Install this extension. If you are asked if you would like to install a "languageserver" R package during this process, select "Yes". If this option does not appear during installing this extension, make sure you install this R package afterwards. - I recomment that you also install the "R Debugger" and "R Syntax" extensions as well;
- If you previously have not been asked to install the languageserver package, you need to install it now. Open a terminal window (if it is not opened already) and start R, by typing
Rat the prompt. Once R session has started, you can typeinstall.packages("languageserver") - Troubleshooting If you are unable to start an R session, you may need to specify the path to where R is installed on your computer. Find the Path to your R installation. On Mac, you can open a terminal window and type:
which R. On a Windows computer, openRorRStudioand in the Console window typeR.home("bin"). Copy this path and then open a "Command Palette" window and typePreferences: Open User Settings (JSON)and select the corresponding line. Make sure you select the(JSON)option, not the(JSONS)option. At the bottom of the file, before the last { bracket, add the following lines:
"r.rterm.option": [
"--no-save",
"--no-restore",
"--r-binary=/your/path/to/R",
],
If the file is empty, make sure you add the {} brackets around your inserted line, so the final file, looks like:
{
"r.rterm.option": [
"--no-save",
"--no-restore",
"--r-binary=/your/path/to/R",
],
}
Make sure that the path of the --r-banary option is set to your path. On Windows computers, the path will look like C:\Program Files\R\R-4.5.2\bin\x64\R.exe. Make sure that you change the backslash characters \ to the forward slash characters / or use double-slash characters \\.
On Mac computers the R installation path may look like: /usr/local/bin/R.
VS Code R Help: https://code.visualstudio.com/docs/languages/r
Optional: You may want to set your R to use Radian. This will enable color-code-highlighting in your terminal window.
- Go to the Extensions view by clicking the square icon in the Activity Bar on the side, or by pressing
Ctrl+Shift+X. - Search for "GitHub Copilot" in the search bar.
- Select the official GitHub Copilot extension (and GitHub Copilot Chat).
- Click the Install button for the selected extensions.
- Once installed, the extension will prompt you to sign in to your GitHub account to activate it:
- A pop-up may appear automatically asking you to Sign in to use Copilot. Select this option.
- Alternatively, you can click the "Copilot icon" in the status bar at the bottom of the VS Code window (it might have a sign-in prompt) and select Set up Copilot or Sign in.
- You can also open the Command Palette (
Ctrl+Shift+P) and type "GitHub: Sign In" to manage your accounts.
- Authorize VS Code:
- A browser window will open, redirecting you to a GitHub authentication page.
- Sign in with your GitHub credentials if prompted.
- Click "Authorize Visual Studio Code" (or Continue and then Allow) to grant the necessary permissions to the GitHub Copilot extension.
- You may see a prompt in the browser asking to open the link in Visual Studio Code. Click "Open Visual Studio Code" (or a similar confirmation) to return to the application.
- Back in VS Code, a final pop-up may appear asking to allow the extension to open a URI. Click Open.
In VS Code, your "Personal Agent" is powered by Custom Instructions. This ensures Copilot understands your specific coding standards (e.g., "Use Tidyverse for R" or "Always include a LIBNAME statement in SAS").
Setup:
- Open Settings -> Settings and in the search bar, type: "GitHub Copilot Instruction File". Make sure that the corresponding checkbox (Controls whether code instructions from
.github/copilot-instructions.md) is checked. - Create the
.githubsub folder in the root of your project folder. - Inside
.github, create a file named copilot-instructions.md. - Use natural language, add your rules. For example:
"When writing R, prefer the pipe operator|>and the dplyr package. For SAS, always use upper-case for PROC and DATA steps and include comments for every DATA step."
Global Instructions:
If you want these rules (or some of these rules) across all projects:
- Go to Command Palette and search for
Chat: New Instructions Fileand select it. - Select "User Profile" or "User Data" in the drop-down menu when prompted to create the file in your global settings folder.
| Action | Windows / Linux | macOS |
|---|---|---|
| The Essentials | ||
| Open Command Palette | Ctrl + Shift + P |
Cmd + Shift + P |
| Open Settings (UI) | Ctrl + , |
Cmd + , |
| Open Integrated Terminal | Ctrl + ` |
Ctrl + ` |
| Toggle Sidebar Visibility | Ctrl + B |
Cmd + B |
| R Programming | ||
| Run Selected Line/Code | Ctrl + Enter |
Cmd + Enter |
| SAS Programming | ||
| Run Selected SAS Code | F3 (or Alt + S) |
F3 (or Option + S) |
| Clear SAS Log | Ctrl + L |
Cmd + L |
| GitHub Copilot | ||
| Open Copilot Inline Chat | Ctrl + I |
Cmd + I |
| Open Copilot Chat Sidebar | Ctrl + Alt + I |
Cmd + Option + I |
| Accept Ghost Text (Suggestion) | Tab |
Tab ** |
| Next/Prev Suggestion | Alt + [ or ] |
Option + [ or ] |
| Git & Version Control | ||
| Open Source Control Tab | Ctrl + Shift + G |
Ctrl + Shift + G |
| Markdown & Documentation | ||
| Open Preview to the Side | Ctrl + K then V |
Cmd + K then V |
| Toggle Full Preview | Ctrl + Shift + V |
Cmd + Shift + V |
