| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
TemplatesTemplates are the Multi-Edit term for "those dear little things that save me so much typing and looking up of passed value orders for functions". This feature is similar to the MASK function for ISPF and the abbreviation list for VI. It allows you to type a few characters (keyword) to generate syntactically correct code with "fill in the blank" areas. Templates (other than smart templates) expand with the same capitalization as that of the keyword you typed. The templates contain text surrounded in the "back leaning" quote mark. These represent code pieces that must be entered to suit the specific requirements for this location. They are called field strings. You can use Cntl-i to hop to the next field string beyond the cursor. When you do this the enclosed text and the back-quotes are highlighted. This means you just type the actual value and the quoted "hint" is replaced. This is a very quick way to fill in a structure or function call without having to look up function parameter order. No use of arrow keys required. Of course, you can change Cntl-i to any key combo you want through . User InformationThere are two templates that you need to customize for your situation. Other templates and macros use these templates. The template Company_name should be changed to the name of the company or organization you want to use in the prolog template. It should only consist of one line. The Programmer_Name template needs to be changed, and must also remain as a single line. Change it to the name of the programmer you want to use in the prolog and maint templates. You can change these by selecting and then picking these two templates off of the scrollable list. Edit them by typing in the small edit box to the right. Code StatementsThese templates are useful for dropping a structured conditional statement into your code. Most of the popular statements are included. In this case the keywords to type, followed by a space, have been kept short and given a consistent pattern. To invoke the template type the key followed by a blank. The names can be used to look up the templates in . Conditional Statement TemplatesIf statements:Key: ift Name: if-then if `condition` then do; `statement`; end;/*if*/ Key: ife Name: if-then-else if `condition` then `statement`; else `statement`; Key: iftd Name: if-then-do if `condition` then do; `statement`; end;/*if*/ Key: ifed Name: if-then-do-else-do if `condition` then do; `statement`; end;/*if*/ else do; `statement`; end;/*else*/ Key: ifs Name: subsetting if if `condition`; Do Statements:Key: dow Name: do-while do while `condition`; `statement` end;/*while*/ Key: dou Name: do-until do until `condition`; `statement` end;/*until*/ Key: dot Name: do-to do `var` = `start` to `end`; `statement` end;/*loop*/ Key: dotb Name: do-to-by do `var` = `start` to `end` by `inc`; `statement` end;/*loop*/ Key: doo Name: do-over do over `array`; `statement` end;/*loop*/ Global Statement TemplatesKey: libname Name: libname libname `libref` '`physical-file/directory`' `access=readonly`; Key: libnamec Name: libname clear libname `libref` clear; Key: filename Name: filename filename `fileref` '`physical-file/directory`'; Key: filenamec Name: filename clear filename `fileref` clear; Key: optd Name: Options for debugging options source source2 macrogen symbolgen mprint; Data StatementsSome of the more common forms of data steps have been added as templates. The dataset id and variable locations have been set up with field strings. The basic forms provided are listed below. In all cases your cursor is placed after the data operator upon expansion of the template. DatabyInvoked by typing databy followed by a space. You can type as little as datab. The following statements result from the template expansion. data `new-dataset` ;
set `dataset`;
by `field`;
run;
DatamergeInvoked by typing datamerge followed by a space. You can type as little as datam. The following statements result from the template expansion. data `new-dataset` ;
merge `dataset1` `dataset2` ;
by `variable`;
run;
DatacardInvoked by typing datacard followed by a space. You can type as little as datac. The following statements result from the template expansion. data `new-dataset` ;
input `variable`;
cards;
`card-data`
;
run;
FunctionsA complete set of templates for SAS functions are provided with EZRTools;). You invoke a function template by typing the name of the function, followed by an open parenthesis, followed by a blank. If you typed dhms( the following code is created. The first parameter will be selected, ready to be replaced by typing. dhms(`date`,`hour`,`minute`,`second`)Note, for Multi-Edit to recognize the template keyword, such as dhms( above, it must have a blank, or beginning of line before the "d". Wrong:x=dhms( |
x= (dhms( |
x= 3+dhms( |
Right:x= dhms( |
x= ( dhms( |
x= 3+ dhms( |
Debug Put AllInvoked by typing dputa followed by a space at the end of the line that you are interested in. The following sets of statements show the result from the template expansion. Note that the line that the template was expanded on plus it's line number (272 in the first example) are included in the debug output. The inclusion of the word "debug" allows these temporary statements to be easily found in the code (to remove when fixed or comment out ). The inclusion of *DBE allows the collapse tools for log files to identify the complete contents of debug put generated output. In the log output you can hide everything but your debug statements. See "Sub-setting the Log" for more information on hiding lines in the log file. Before:
retain state city county country "USA"
salu "Mr." firstn lastn mi |
active 0 calls cmonth cyear
expen salry ;
After:
retain state city county country "USA"
salu "Mr." firstn lastn mi
active 0 calls cmonth cyear
expen salry ;
PUT 'Debug after: 272 : salu "Mr." first... <<<<<<<<<<<<<<<<<<<<<<<<<<' /
_ALL_' *DBE' / ;
Before:
retain state city county country "USA" dput|
salu "Mr." firstn lastn mi
active 0 calls cmonth cyear
expen salry ;
After:
retain state city county country "USA"
salu "Mr." firstn lastn mi
active 0 calls cmonth cyear
expen salry ;
PUT 'Debug after: 271 : retain state cit... <<<<<<<<<<<<<<<<<<<<<<<<<<' /
_ALL_' *DBE' / ;
Debug Put VariablesThis variation is invoked after first selecting one or more variables or lines. You can then select from the context sensitive menu (right click in edit area) or press Cntl-Shift-d. The tool will identify variable names that are not the same as a SAS keywords or function names. The following sets of statements show various results from the different uses of this tool. Note that the highlighted line plus it's line number (272 in the first example) are included in the debug output. The inclusion of the word "debug" allows these temporary statements to be easily found in the code (to remove when fixed or comment out). The inclusion of *DBE allows the collapse tools for log files to identify the complete contents of debug put generated output. In the log you can hide everything but your debug statements. See "Sub-setting the Log" later in this document for more information on hiding lines in the log file. Before:
retain state city county country "USA"
salu "Mr." firstn lastn mi
active 0 calls cmonth cyear
expen salry ;
After:
retain state city county country "USA"
salu "Mr." firstn lastn mi
active 0 calls cmonth cyear
expen salry ;
PUT 'Debug after: 272 : salu "Mr." first... <<<<<<<<<<<<<<<<<<<<<<<<<<' /
salu=
firstn=
lastn=
mi=
' *DBE' / ;
Before:
retain state city county country "USA"
salu "Mr." firstn lastn mi
active 0 calls cmonth cyear
expen salry ;
After:
retain state city county country "USA"
salu "Mr." firstn lastn mi
active 0 calls cmonth cyear
expen salry ;
PUT 'Debug after: 274 : retain state cit... <<<<<<<<<<<<<<<<<<<<<<<<<<' /
state=
city=
county=
country=
salu=
firstn=
lastn=
mi=
active=
calls=
cmonth=
cyear=
expen=
salry=
' *DBE' / ;
Before:
if calls = 0 then do;
active = 0;
end;/*if*/
After:
if calls = 0 then do;
PUT 'Debug after: 284 : if calls = 0 the... <<<<<<<<<<<<<<<<<<<<<<<<<<' /
calls=' *DBE' / ;
active = 0;
end;/*if*/
Before:
do i = 1 to 100 by 5;
old = x;
x = new;
new = offset + i;
end;/*do loop*/
After:
do i = 1 to 100 by 5;
old = x;
x = new;
new = offset + i;
end;/*do loop*/
PUT 'Debug after: 297 : end;/*do loop*/ <<<<<<<<<<<<<<<<<<<<<<<<<<' /
i=
old=
x=
new=
offset=
' *DBE' / ;
Before:
do i = 1 to 100 by 5;
old = x;
x = new;
new = offset + i;
end;/*do loop*/
After:
do i = 1 to 100 by 5;
old = x;
x = new;
PUT 'Debug after: 295 : old = x; <<<<<<<<<<<<<<<<<<<<<<<<<<' /
old=
x=
new=
' *DBE' / ;
new = offset + i;
end;/*do loop*/
Before:
expn = (cost1 + (2.3 * cost2)) - round(cost3,1);
After:
expn = (cost1 + (2.3 * cost2)) - round(cost3,1);
PUT 'Debug after: 284 : expn = (cost1 + ... <<<<<<<<<<<<<<<<<<<<<<<<<<' /
expn=
cost1=
cost2=
cost3=
' *DBE' / ;
Commonly Used ProcsTemplates exist for most commonly used procs, with the most common sub statements, options etc. represented. You can invoke the template by typing a "p" followed by the name of the procedure followed by a space. For instance, if you typed pappend followed by a blank, you would get the following expansion. The out= value will be selected so that you may immediately overtype it. As always, you can hop to the next parameter using Cntl-i. The spell proc has 2 forms pspell and pspelld for dictionary modification. proc append out=`sas-dataset` data=`sas-dataset` ` CommentsThe following templates are related to in-code documentation. The comment blocking templates cbline, cbk, cbk2, and cbk3 are discussed in the Edit Tools section. This section will discuss the prolog and maint templates. PrologThis template produces a prolog that can contain program and maintenance information. When you expand the template you are prompted for a program name and a description. These are fitted into the top section of the prolog. The middle section contains user information from the Programmer_Name and Company_Name templates plus copyright information based on the current system date. The bottom section is set up to hold update, bug fix and other maintenance information (see the maint template below). An example follows. /******************************************************************/ /******************************************************************/ /*** Program Name: Hasher **/ /** **/ /******************************************************************/ /*** Description: My wonder full program that hashes everything ***/ /*** until it is broken. ***/ /******************************************************************/ /*** **/ /*** **/ /*** **/ /*** Created: 02/28/2000 3:47:15PM **/ /*** By: Art Bitt **/ /*** Copyright c2000 Basement Software All rights reserved. **/ /*** **/ /******************************************************************/ /*** Maintenance Notes **/ /*** Name Date Time Change Code **/ /******************************************************************/ /******************************************************************/ MaintThis template adds records to the maintenance section of the prolog. Place your cursor after the comment symbol at the end of the last maintenance line. Press enter and type maint followed by a space. You will be prompted for a reason for the change and maintenance or change code. The programmer name and date are automatically filled in as in the prolog. An example of what is inserted below. Before:/*** **/
/******************************************************************/
/*** Maintenance Notes **/
/*** Name Date Time Change Code **/
maint |
/******************************************************************/
/******************************************************************/
After:/*** **/ /******************************************************************/ /*** Maintenance Notes **/ /*** Name Date Time Change Code **/ /*** Art Bitt 02/28/2000 3:48:29PM 000000 **/ /*** Broken what-ja-ma-callit. **/ /******************************************************************/ /******************************************************************/ End Of Line CommentsYou can place comments after a code statement very easily with the end of line comments ComEndOfLine and ComEOLDate. The ComEndOfLine , invoked with /* followed by a blank at the end of line, tabs right once and places the text /* */ on the line. Your cursor is placed one space after the /* characters. The ComEOLDate template works the same except it puts a Date/Time stamp at the end of the comment. It is invoked with the characters /*d followed by a blank. Examples of both templates are listed below. Before: w= log(x); /* |
After: w= log(x); /* | */
Before: r= w + 1; /*d |
After: r= w + 1; /* | 04/05/00 12:03:PM */
Comment UncommentYou can comment out a block of code by selecting it with the mouse, and invoke the menu item from the selection of the context sensitive menu. This function can also be invoked by pressing Cntl-O, or select the button from the SAS toolbar. Any comments within the block of code are altered to prevent them from effecting the commented out block. This conversion is easily removed by using the same function on that block of code again. If you have previously used this function on a block of code, you can remove the comment blocking. Select the block of code, including the beginning and end block. If you select more lines beyond the end block comment, the operation is unaffected. You must include the beginning comment. Then invoke this function as indicated above and the comments will be removed and any contained comments will be returned to their original form. Smart TemplatesSmart templates are templates for some of the more complex and option ridden procs or standard option lists. The invocation of these type of templates differs little from the standard procs, except that you follow the procs name with a *. So if you wanted the smart template for proc compare you would type compare* , followed by a space. When you do this you are presented with a series of checkbox dialogs that allow you to select the options, statements, and statement options that you require. The expansion into a proc statement will include the items you selected and any needed parameters. Parameters are represented as field strings. The following procs are implemented as smart templates.
Other common options.
Function CascadeFunction Cascade is a template invoked, menu driven method to invoke a function template by picking it from a list. You start the process by typing f() preceeded and followed by a blank at the place where you want the function call to appear. You will be presented with a popup menu. This menu presents a list of major groups of functions. As you make selections the last popup disappears and a new one appears in its place listing a subset of groups or actual function names. You may select the "Forget it" entry at any time to abort the process. The initial menu breaks all the functions into the following groups.
The entries, I/O, Strings and Math in the first menu have sub menus with sub groups listed. The sub menus and their descriptions are listed below. Input, Output
Strings
Mathematics
Help TemplatesHelp templates are set up to provide code expansion that contains all the options for the statement in question. Often the code is accompanied by comments with further information. They may expand to multiple calls of the item in each of the major flavors. This form allows you to delete the unwanted flavors/comments. The following topics have help templates available. Help templates are invoked by using the name of the statement preceded with a ? mark.
Below are a few examples of the code that results from help template expasion For ?libname:LIBNAME `LIBREF` '`SAS-DATA-LIBRARY`' <HOST-OPTIONS>; LIBNAME `LIBREF` CLEAR; /*DISASSOCIATE*/ LIBNAME `LIBREF` |_ALL_ LIST; /*LIST ATTRIBUTE, PRINT TO LOG */ For ?dataset:(COMPRESS=`NO|YES`
DROP=`VARIABLE-LIST`
FIRSTOBS=`N`
IN=`VARIABLE`
INDEX=`INDEX``<=VARIABLE-LIST>` `</UNIQUE>` `</NOMISS>` `<...>`
KEEP=`VARIABLE-LIST`
LABEL=`LABEL`
OBS=`N`
RENAME=(`OLD-NAME1`=`NEW-NAME1` `<...>`)
WHERE=(`WERE-EXPRESSION`)
);
for ?infile:INFILE `'EXTERNAL-FILE'/FILEREF/FILEREF(FILE)/CARDS` <OPTIONS> <HOST-OPTIONS>; /* OPTIONS: BLKSIZE=SIZE;COL=VARIABLE;DELIMITER=DELIM-CHAR-LIST;END=VARIABLE; */ /* EOF=LABLE;EOV=VARIABLE;EXPANDTABS;NOEXPANDTABS;FILENAME=VARIABLE; */ /* FILEVAR=VARIABLE;FIRSTOBS=RECORD-NUMBER;FLOWOVER;LENGTH=VARIABLE; */ /* LINE=VARIABLE;LINESIZE=SIZE;LRECL=LENGTH;MISSOVER;N=AVALABLE-LINES; */ /* OBS=RECORE-NUMBER;PAD;NOPAD;PRINT;NOPRINT;SHAREBUFFERS; */ /* RECFM=RECORD-FORMAT;START=VARIABLE;STOPOVER;TRUNCOVER;UNBUFFERED */
Copyright © 2000- , Martin Works Inc., Text, graphics, and HTML code are protected by US and International Copyright Laws, and may not be copied, reprinted, published, translated, hosted, or otherwise distributed by any means without explicit permission. SAS® is a registered trademark of SAS Institute, Inc. in Cary, NC. Multi-Edit® is a trademark of Multi-Edit Software Inc. All other logos and trademarks in this site are property of their respective owners. |