Save Typing And Add Abbreviation In SAS

SAS Abbreviation ExampleDo you have those snips of SAS code you run over and over again? I do. However, I do not type the entire thing into my editor anymore (I did that for way too long). Instead, I add abbreviations to my SAS editor. Consequently, I save a lot of unnecessary typing and get the job done faster. In this short post, I demonstrate how to add and utilize abbreviations in SAS.

Two Abbreviation Examples

An abbreviation in SAS is a piece of code that you save in your editor and generate with a specified keyword. Usually, the piece of code is frequently used. Therefore you save time and effort because you do not have to type the entire code each time you want to use it.

To save an abbreviation go to Tools –> Add Abbreviation. A pop-up window appears with two input boxes. In the first box, type the abbreviation name. This is the abbreviation under which you save the actual code. To avoid confusion, I prepend my abbreviations with an underscore. In the second box, paste the code you want to appear when you type the abbreviation name from the first box. Lastly, hit ok.

Let us look at an example of a typical use of abbreviations. I like the Hash Object. I use it frequently and the declaration statements are almost identical every time. Consequently, this is an obvious case where an abbreviation comes in handy. Below is the code that I have associated with the abbreviation _hash (see my abbreviation list to the right).

if _N_ = 1 then do;
   declare hash h();
   rc = h.defineKey('k');
   rc = h.defineData('d');
   rc = h.defineDone();
   call missing(k, d);

As another example, I have previously shown how to Delete All Data Sets In Work Library with simple SAS code. This is another obvious choice of an abbreviation. Below is the code I have associated with the _killwork abbreviation.

proc datasets lib=work nolist kill;

While the _hash abbreviation can be seen as a template that will be modified when inserted, the _killwork abbreviation is a bit different. I almost never change the code. I simply run it. Therefore this is a good candidate for adding a hotkey. That way, you do not even have to insert the code. You simply associate a set of hotkeys to the abbreviation. In a future post, I will write about how to Add Hotkeys To SAS Abbreviations. Thus saving even more precious coding time.


Adding abbreviations in your SAS editor is a great way to save typing and get the job done faster. If you run the same code again and again, there is no need to type the code over and over. Take control and let your editor do the dirty work. I have previously written about a classical use of abbreviations in the post Standard SAS Header Example.

You can download the entire code from this post here.