Sas Abbreviations

Save Time and Effort: Leveraging Abbreviations in SAS EG for Code Reusability

  • Post author:
  • Post category:Base SAS
  • Post comments:0 Comments
  • Reading time:7 mins read

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.

sas 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.

sas-abbreviations

Paste the code into the “Text to insert” section and choose an easy-to-remember abbreviation in the “Abbreviation” section.

sas-abbreviations

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.

Using SAS Abbreviation

Changing or Deleting SAS Abbreviation

To Edit or delete abbreviations. Select the Program menu and then Manage macros and snippets.

Changing or Deleting Your Abbreviation
Changing or Deleting Your Abbreviation

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.

Save Time and Effort: Leveraging Abbreviations in SAS EG for Code Reusability

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.

Sharing and Exporting SAS Abbreviations
Sharing and Exporting SAS Abbreviations

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.

Conclusion

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.

Every week we'll send you SAS tips and in-depth tutorials

JOIN OUR COMMUNITY OF SAS Programmers!

Subhro

Subhro provides valuable and informative content on SAS, offering a comprehensive understanding of SAS concepts. We have been creating SAS tutorials since 2019, and 9to5sas has become one of the leading free SAS resources available on the internet.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.