It is not laziness—it is efficiency!!! Programmers are often called lazy; we even call ourselves lazy. But we are not lazy, we are just being efficient. It makes no sense to type the same code over and over again or use more keystrokes than are absolutely necessary.
Keyboard Macros
Macros are sequences of events (such as keystrokes, mouse clicks, and delays) that can be played back to help with repetitive tasks. They can also be used to replay sequences that are long or difficult to run. You can assign a macro recorded in Microsoft Mouse and Keyboard Center to a key or a mouse button. Keyboard macros are a powerful Emacs feature. A keyboard macro is simply a recording of a sequence of key sequences. A key sequence is a series of keyboard keystrokes, mouse actions, or menu actions that is bound to an Emacs command. So, a keyboard macro records a sequence of user actions that carry out Emacs commands.
You might not have heard of keyboard macros. Or, perhaps, you do not know how they could help you. I am very fond of keyboard macros; let me show you why!
- Macros are meant to be simple.? You can also use the functions described in Useful function and Checking modifier state for additional functionality. For example, resetkeyboard allows you to reset the keyboard as part of a macro and getmods & MODMASKSHIFT lets you check for the existence of active shift modifiers.
- Redragon K585 DITI Wireless One-Handed Mechanical Keyboard, 42 Keys 2.4Ghz RGB 40% Gaming Keypad with 7 Onboard Macro Keys, Detachable Wrist Support, 3000 mAh Battery Redragon K556 RGB LED Backlit Wired Mechanical Gaming Keyboard, Aluminum Base, 104 Standard Keys.
In SAS Technical Support, supporting the SAS® Output Delivery System (ODS) and Base SAS® procedures, I often use the same statements to set up test programs. For example, I want any style templates that I create to go into the Work directory. I also use the same data set name all of the time. I have created keyboard macros for the statements, data set names, and options that I use daily.
When I press Ctrl+Alt+w, the following is inserted into my program:
When I press Ctrl+Alt+p, the following is inserted into my program:
sashelp.class
How did I do that? I recorded a keyboard macro that contains the code that I want. Then, I assigned keys that insert the code when I press them.
Here are the steps for recording your very own keyboard macro in the SAS Enhanced Editor:
1. Select Tools ► Keyboard Macros ► Record New Macro.
2. Enter the code that you want to be your new keyboard macro. Consider typing slowly because any backspaces that you use are included in the recording.
3. After you are done entering text, you need to tell SAS to stop recording. Select Tools ►Keyboard Macros ►Stop Recording.
4. A pop-up dialog box appears that lets you give the new macro a name and assign the keys that you want to be associated with the macro. You can set the key combination that make sense to you. Just make sure that you do not use a combination that is already assigned to another macro.
Now, whenever you need to insert that piece of code, just use the keys that you assigned!
In SAS® Enterprise Guide®, you can find keyboard macros under Program ► Editor Macros, instead of the Tools drop-down menu. The recording and key assignment steps are the same in both applications.
Macros For Any Keyboard
You can also create keyboard macros that perform tasks.
The Macros selection opens a pop-up dialog box that contains a Create button.
Clicking Create opens another dialog box.
With the Categories option set to All, you can see all of the commands that are already available. Moving these over to the Keyboard macro contents section enables you to build a macro that performs a task that you need to accomplish on a regular basis.
For example, I have combined these commands to select a whole block of code, like from the PROC statement down to the RUN statement.
Keyboards macros are available in the Enhanced Editor in Display Manager SAS (DMS) and in SAS Enterprise Guide. They cannot be used with the Program Editor in DMS or in SAS® Studio.
You can export and import keyboard macros. The file created when you export has the .kmf extension. You can find the options for importing and exporting in the Macros dialog box. You can share your keyboard macros with your friends, or just to keep them as a backup copy in case you need to reinstall SAS.
For more information, see the Using 'Keyboard Macros' section in 'Using the Enhanced Editor.'
Function Keys
You have probably used the F8 key to submit your program, or the F4 key to recall your last program. Did you know that you can set or change those instructions?
In the Enhanced Editor, you can get the list of assigned keys by entering keys into the command bar or by selecting Keys under Tools ► Options.
I test a lot, which means that I am routinely clearing the log, the results viewer, and the output window. I have assigned an F key, F12, to clear everything and bring the focus back to the Enhanced Editor (see the commands in the screenshot below). I have to press only one key to clean everything up! I use the F12 key over and over again.
The keys that you assign in DMS are valid from both the Enhanced Editor and the Program Editor.
SAS Enterprise Guide includes a large number of commands by default. A lot of them already have keys assigned, but some do not. You can see the list of the commands and their assigned keys by selecting Enhanced Editor Keys under the Program drop-down menu.
Currently, it is not possible to modify the function keys in SAS Studio. However, a number of keys are already defined that you might find useful. You can see the function key shortcuts by clicking the question mark in the upper right, choosing SAS Studio help, and then selecting the option for Accessibility Features. Here are links to additional resources:
I highly recommend using keyboard macro and function keys. Why type the same thing over and over again? Increase your productivity by handing the repetitive tasks over to SAS.