Creating Keyboard and Toolbar Shortcuts in SAS
You can create SAS keyboard shortcuts and toolbar buttons to instruct SAS to perform a set of tasks. For example, if you like to clear your log, output, and results in windows before executing new commands, you might set up a shortcut or button to instruct SAS to do all of those tasks, with just the press of a key or click of a button.
You can create SAS keyboard macros to let you easily insert frequently used text into the Enhanced Editor window. For example, you might use this to enter the commands for a favorite Proc step or Data step.
These facilities can be great time savers.
-
How to Create a Keyboard Shortcut (to perform a set of tasks)
-
How to Create a Toolbar Button (to perform a set of tasks)
-
How to Create a Keyboard Macro (to insert text into the editor window)
How to Create a Keyboard Shortcut
- Make sure the Enhanced Editor window is the active SAS window.
- From the toolbar, select Tools --> Options --> Keys.
- Scroll down to the keystroke you would like to assign to the series of tasks, looking for a keystroke that has no current assignment. For example, scroll down to F12, which represents the F12 key on your keyboard, or to SHF F12, which represents pressing Shift-F12.
- Add your desired task commands under the Definition heading for that keystroke. For example:
log; clear; output;clear; odsresults; clear; wpgm; submit;
Those commands instruct SAS to go to the Log window and clear it, then go to the Output window and clear it, then go to the Results Viewer window and clear it, then go to the program editor window and submit the code found there. See the SAS documentation for additional commands that can be used in keyboard shortcuts.
- Close the Keys window.
Now, pressing the assigned keystroke will perform the designated set of commands. The keystroke is available in the Log, Output and Enhanced Editor windows.
Notes about creating SAS shortcuts:
- If there are multiple editor windows open, the keystroke will resubmit code for the editor window that the user is currently in.
- If there are multiple editor windows open and the user is not in an editor window, the keystroke will submit whatever program code that is highlighted.
- If no program code is highlighted, the keystroke defaults to the first editor window.
- This assignment will remain until it is changed or deleted. (The shortcut is retained even when you close/open your SASĀ® session).
How to Create a Toolbar Button
- Make sure the Enhanced Editor window is the active SAS window.
- From the toolbar, select Tools --> Customize.
- In the pop-up window, choose the Customize tab.
- Select the Add tool icon (left-most icon in the second row).
- Enter the series of commands in the command box:
For example: log; clear;odsresults;clear;output;clear;wpgm; submit; - Type a description of your icon in the Help text box
For example: Clears log and output windows and resubmits code in editor window. - Select the Change Icon button (third icon in the second row).
- Choose the icon you would like to associate with your series of commands.
- Select OK.
- When asked, "Do you want to save your changes to SASUSER.PROFILE.SASEDIT_MAIN?",
Select YES you would like to save the changes made.
Notes about creating toolbar buttons:
- The new icon should now appear on your Enhanced Editor window toolbar.
- If there are multiple editor windows open, the icon will submit code from the editor window that the user is currently working in.
- The Output window and the Log window each have their toolbars.
- Should you want a shortcut icon in both the Output and Log windows, you will need to create the icon using the steps above once in each window.
How to Create a Keyboard Macro
An SAS keyboard macro can help you easily insert a command or set of commands (or any text) into the Enhanced Editor window. This can be a great time saver. For example, you might want to use this to insert the commands for a favorite Proc step or Data step.
Once a macro is created, its text can be inserted into the editor window at any time by just typing the macro's abbreviation (name) or by pressing a keyboard shortcut that you have assigned to the macro.
To create a macro, do the following:
- First, copy into the Windows clipboard the text that you want to assign to this macro. For example, type the text into the editor window, select the text with your mouse, then right-click it and choose 'Copy.' Any amount of text can be assigned.
- Make sure the Enhanced Editor window is the active SAS window.
- Now display the Tools menu and select 'Add Abbreviation' (or press the key combination Control-Shift-A). This will display the Add Abbreviation window. In this window, do the following:
- In the Abbreviation box, type a short abbreviation for the macro. Later, when you want to insert your text, you will type this abbreviation in the editor window.
- In the large box, right-click and choose 'Paste' to insert your desired text (that you had copied to the Windows clipboard in step 1 above).
- Click OK.
Your macro is ready to use. In the editor window, whenever you now type your macro's abbreviation, you will see a pop-up display of the text stored in the macro. To insert that text into the editor window, press the Tab or Enter key. Or, you can just keep typing, if you do not want to add the macro's text.
If you wish to edit your macro or assign a keyboard shortcut to it (so that pressing that keyboard shortcut will instantly insert the text), display the Tools menu and select 'Keyboard Macros' and then 'Macros' (or press the key combination Control-Shift-M). The Keyboard Macros window will display so that you can modify this and any other macros that you have created.
For more information, please see (for example) Keyboard Macros.
This article was updated: 04/27/2020