| Using abbreviations to quickly generate SAS code in the Enhanced Editor |
|
|
|
|
[The following was inspired by a paper by Paul Grant at the SAS Institute Support Team. The full text of the paper is available at http://support.sas.com/sassamples/papers/0303_saseditor.pdf.] There's a function in the SAS Enhanced Editor (version 8 and later) that allows you to create abbreviations. Whole chunks of code can be assigned to a single word abbreviation. So when you type the single word in the Enhanced Editor, a box pops up showing you the chunk of code associated with it. If you want to use the code, you hit or , if you don't want to use the code you just keep typing. It's really simple to set up the shortcuts/abbreviations. In the SAS Enhanced Editor, go to Tools -- > Add Abbreviation... Then you just type in the shortcut word you want to use, and copy and paste in the chunk of code to associate with that word. Click OK and you are good to go. The abbreviation WILL exist in all future sessions of SAS. I've found three places the abbreviations have proven to be amazingly helpful. Use #1 We have several standard macros we use in our programming. But I can never keep track of the exact syntax for the macro calls. Now I've set up abbreviations for each of the standard macros, so when I begin to type the macro call, the chunk of code for the exact syntax pops up and all I have to do is hit and fill in the blanks. For example, we have a macro called %mkxpt, for which the syntax looks like this: %mkxpt(srclib=work, srcds=, xptpath=, xptds=, dopc=Y, dslbl=, strpfmt=Y); I set up an abbreviation named '%mkxpt' with the chunk of code above associated with it. Now as soon as I type %mkxpt, the text box pops up with the complete code above. I hit enter, the complete code appears in the program and I just fill-in or change the parameters as appropriate. Use #2 We have a set of standard macros to use. But sometimes our clients request self-contained programs, meaning we cannot use our macro library directly. So if we want to use any of our standard macros in the programming, we have to put the complete macro within the body of the program. I used to do this by going to the macro library, copying the entire body of the macro and pasting it into my program. Now I've set up an abbreviation for the most commonly used of the standard macros and any time I want to include them I just type the shortcut and get the whole macro body. Use #3 Some PROCs I can just not ever remember the exact syntax. I have to go digging in the SAS documentation or old programs every time I want to use them. PROC IMPORT and PROC EXPORT are two with which I have the most difficulty. Is it 'outfile' or 'infile'? Is it 'replace' or 'old'? I'm constantly getting jumbled up and getting it wrong. But now I have two abbreviations, one named 'proc import' and one named 'proc export'. So as soon as I begin to type the proc, the rest of the required information pops up in a text box, I hit and fill-in the syntax as appropriate. Courtesy of: AYW Consulting. More tips at www.sastips.com. |
|
| Last Updated ( Thursday, 06 September 2007 ) |













