Table of Contents Hide
Do you ever feel the need to refer to documentation while dealing with a particular procedure or function’s syntax? Is there a specific block of code that has become a regular part of your programming routine? Also, what about the monotonous task of adding a detailed comment block or library names at the start of your programs?
This blog post demonstrates how to create and use SAS abbreviations to quickly add code snippets to the Editor window.
What Are Sas Abbreviations?
A SAS abbreviation is a custom-defined character string that replaces a longer text string when typed in the Editor window. This can be especially useful when the longer text string is a piece of SAS code.
There are two parts of the abbreviation. The first part is the abbreviation you want to be able to quickly automate. The second part is a code snippet.
When you type the abbreviation into the Editor window, SAS will prompt you to use the abbreviation.
Abbreviations are a feature in SAS EG that allows you to save time and keystrokes when writing code. For instance, instead of writing the whole PROC EXPORT step, you can write export. Similarly, instead of writing DATA=, you may use D=.
Creating an Abbreviation
Copy the code that you want to reuse and create a snippet.
Select ‘New Snippet’ from the Programs menu or use the shortcut Ctrl+Shift+A.
Note: For older versions of the SAS Enterprise guide you might have to use the keyboard shortcut only to create new abbreviations.
After clicking on the abbreviation creation button, a new window will appear where you need to enter the name of the abbreviation and the corresponding text that should be inserted by SAS into the editor when the abbreviation is used.
Paste the code into the “Text to insert” section and choose an easy-to-remember abbreviation in the “Abbreviation” section.
Click OK to save the abbreviation.
Using SAS Abbreviation
To use the abbreviation, place the cursor where you want to insert your code. Type the name you assigned when creating the abbreviation.
Changing or Deleting SAS Abbreviation
To Edit or delete abbreviations. Select the Program menu and then Manage macros and snippets.
A window opens. Click on the abbreviation you want to change or delete so it is highlighted.
- If you want to delete the abbreviation, click DELETE.
- If you want to change the abbreviation, click EDIT.
When you click ‘Edit Abbreviation’, a new window will appear with your code at the bottom right. Click on the code to select it.
Sharing and Exporting SAS Abbreviations
You might want to share your abbreviations with others, or perhaps you will need to put your abbreviations on a different computer.
Select the Program menu and then Manage macros and snippets. A window opens where you select the abbreviations to export. This will generate a .kmf file.
To select more than one abbreviation at a time, hold down the CTRL key on your keyboard. You can select all of them by clicking on the first abbreviation, holding down Shift, and clicking on the last abbreviation.
Click the Export button.
Other users can import .kmf in the Manage macros and snippets window.
Utilizing SAS abbreviations can significantly reduce coding time and also minimize the effort required to look up the syntax for various functions, statements, or procedures that you may forget. Moreover, adding a comment header block to your programs is often mandatory to document what they do. This can help you create easily readable code without having to type a template every time or copy-pasting from another program.