1 ESS[SAS] was designed for use with SAS. It is descended from emacs
2 macros developed by John Sall for editing SAS programs and SAS-mode by
3 Tom Cook. Those editing features and new advanced features are part of
4 ESS[SAS]. The user interface of ESS[SAS] has similarities with ESS[S]
5 and the SAS Display Manager.
7 @comment node-name, next, previous, up
8 @node ESS(SAS)--Design philosophy, ESS(SAS)--Editing files, ESS for SAS, ESS for SAS
9 @section ESS[SAS]--Design philosophy
11 ESS[SAS] was designed to aid the user in writing and maintaining
12 SAS programs, such as myfile.sas. Both interactive and batch submission
13 of SAS programs is supported.
15 ESS[SAS] was written with two primary goals.
17 1. The emacs text editor provides a powerful and flexible development
18 environment for programming languages. These features are a boon to all
19 programmers and, with the help of ESS[SAS], to SAS users as well.
21 2. Although a departure from SAS Display Manager, ESS[SAS] provides
22 similar key definitions to give novice ESS[SAS] users a head start.
23 Also, inconvenient SAS Display Manager features, like remote submission
24 and syntax highlighting, are provided transparently; appealing to
25 advanced ESS[SAS] users.
27 @comment node-name, next, previous, up
28 @node ESS(SAS)--Editing files, ESS(SAS)--TAB key, ESS(SAS)--Design philosophy, ESS for SAS
29 @section ESS[SAS]--Editing files
31 ESS[SAS] is the mode for editing SAS language files. This mode handles:
34 - proper indenting, generated by both [Tab] and [Return].
35 - color and font choices based on syntax.
36 - ability to send the contents of an entire buffer, a highlighted region,
37 or a single line to an interactive SAS process.
38 - ability to switch between processes which would be the target of the
39 buffer (for the above).
40 - ability to save and submit the file you are working on as a batch SAS
41 process with a single keypress and to continue editing while it is runs
43 - capability of killing the batch SAS process through the shell buffer or
44 allow the SAS process to keep on running after you exit emacs.
45 - single keypress navigation of .sas, .log and .lst files (.log and .lst
46 files are automatically refreshed with each keypress).
49 ESS[SAS] is automatically turned on when editing a file with a .sas
50 suffix (or other extension, if specified via auto-mode-alist). The function
51 keys can be enabled to use the same function keys that
52 the SAS Display Manager does. The interactive capabilities of ESS require you
53 to start an inferior SAS process with M-x SAS
54 (@xref{iESS(SAS)--Interactive SAS processes}.)
56 At this writing, the indenting and syntax highlighting are generally
57 correct. Known issues: for multiple line * or %* comments, only the
58 first line is highlighted; for .log files, only the first line of a
59 NOTE:, WARNING: or ERROR: message is highlighted; unmatched
60 single/double quotes in CARDS data lines are NOT ignored; in a DO ... TO
61 or a DO ... TO ... BY statement, TOs are not highlighted (and neither is
64 @comment node-name, next, previous, up
65 @node ESS(SAS)--TAB key, ESS(SAS)--Batch SAS processes, ESS(SAS)--Editing files, ESS for SAS
66 @section ESS[SAS]--TAB key
68 Two options. The TAB key is bound by default to sas-indent-line. This
69 function is used to syntactically indent SAS code so PROC and RUN are in
70 the left margin, other statements are indented 4 spaces from the margin,
71 continuation lines are indented 4 spaces in from the beginning column of
72 that statement. This is the type of functionality that emacs provides
73 in most programming language modes. This functionality is equivalent to
74 uncommenting the following line in ess-site.el:
76 (setq ess-sas-edit-keys-toggle nil)
79 ESS provides an alternate behavior for the TAB key that makes it behave
80 as it does in SAS Display Manager, i.e. move the cursor to the next tab
81 stop. The alternate behavior also provides a backwards TAB, C-TAB, that
82 moves the cursor to the tab stop to the left and deletes any characters
83 between them. This functionality is obtained by uncommenting the
84 following line in ess-site.el:
86 (setq ess-sas-edit-keys-toggle t)
88 Under the alternate behavior, the TAB key is bound to tab-to-tab-stop
89 and the tab stops are set at multiples of sas-indent-width.
91 @comment node-name, next, previous, up
92 @node ESS(SAS)--Batch SAS processes, ESS(SAS)--Function keys for batch processing, ESS(SAS)--TAB key, ESS for SAS
93 @section ESS[SAS]--Batch SAS processes
95 Submission of a SAS batch job is dependent on your environment.
96 ess-sas-submit-method is determined by your operating system and your
97 shell. It defaults to 'sh unless you are running Windows or Mac
98 Classic. Under Windows, it will default to 'sh if you are using a
99 Unix-imitating shell; otherwise 'ms-dos for an MS-DOS shell. On Mac OS
100 X, it will default to 'sh, but under Mac Classic AppleScript is used
101 ('apple-script). You will also set this to 'sh if the SAS batch job
102 needs to run on a remote machine rather than your local machine. This
103 works transparently if you are editing the remote file via ange-ftp/EFS
104 or tramp. Note that ess-sas-shell-buffer-remote-init is a Local
105 Variable that defaults to "ssh" which will be used to open the buffer on
106 the remote host and it is assumed that no password is necessary,
107 i.e. you are using the equivalent of ssh-agent/ssh-add (see the
108 discussion about Local Variables below if you need to change the
111 However, if you are editing the file locally and transferring it back
112 and forth with Kermit, you need some additional steps. First, start
113 Kermit locally before remotely logging in. Open a local copy of the
114 file with the ess-kermit-prefix character prepended (the default is
115 "#"). Execute the command ess-kermit-get which automatically brings the
116 contents of the remote file into your local copy. If you transfer files
117 with Kermit manually in a shell buffer, then note that the Kermit escape
118 sequence is C-q C-\ c rather than C-\ c which it would be in an ordinary
119 terminal application, i.e. not in an emacs buffer. Lastly, note that
120 the remote Kermit command is specified by ess-kermit-command.
122 The command used by the SUBMIT function key (F3 or F8) to submit a batch
123 SAS job, whether local or remote, is ess-sas-submit-command which
124 defaults to sas-program. sas-program is "invoke SAS using program file"
125 for Mac Classic and "sas" otherwise. However, you may have to alter
126 ess-sas-submit-command for a particular program, so it is defined as
127 buffer-local. Conveniently, it can be set at the end of the program:
131 ess-sas-submit-command: "sas8"
135 The command line is also made of ess-sas-submit-pre-command,
136 ess-sas-submit-post-command and ess-sas-submit-command-options
137 (the last of which is also buffer-local).
138 Here are some examples for your .emacs file (you may also use
139 M-x customize-variable):
142 (setq ess-sas-submit-pre-command "nohup")
144 (setq ess-sas-submit-post-command "-rsasuser &")
146 (setq-default ess-sas-submit-command "/usr/local/sas/sas")
148 (setq ess-sas-submit-pre-command "start")
150 (setq ess-sas-submit-post-command "-rsasuser -icon")
152 (setq-default ess-sas-submit-command "c:/progra~1/sas/sas.exe")
154 (setq-default ess-sas-submit-command "c:\\progra~1\\sas\\sas.exe")
157 There is a built-in delay before a batch SAS job is submitted when using
158 a Unix-imitating shell under Windows. This is necessary in many cases
159 since the shell might not be ready to receive a command. This delay is
160 currently set high enough so as not to be a problem. But,
161 there may be cases when it needs to be set higher, or could be set much
162 lower to speed things up. You can over-ride the default in your .emacs
165 (setq ess-sleep-for 0.2)
168 For example, open the file you want to work with
169 (ess-sas-global-unix-keys keys shown, ess-sas-global-pc-keys in
170 parentheses; ESS[SAS] function keys are presented in the next section).
174 myfile.sas will be in ESS[SAS] mode. Edit as appropriate, then save and
175 submit the batch SAS job.
179 The job runs in the shell buffer while you continue to edit
180 myfile.sas. If ess-sas-submit-method is 'sh, then the
181 message buffer will display the shell notification when the
182 job is complete. The 'sh setting also allows you to
183 terminate the SAS batch job before it is finished.
187 Terminating a SAS batch in the *shell* buffer.
191 You may want to visit the .log (whether the job is still running
192 or it is finished) and check for error messages. The .log will be
193 refreshed and you will be placed in it's buffer. You will be
194 taken to the 1st error message, if any.
198 Goto the next error message, if any.
202 Now, refresh the .lst and go to it's buffer.
206 If you wish to make changes, go to the .sas file with.
210 Make your editing changes and submit again.
215 @comment node-name, next, previous, up
216 @node ESS(SAS)--Function keys for batch processing, iESS(SAS)--Interactive SAS processes, ESS(SAS)--Batch SAS processes, ESS for SAS
217 @section ESS[SAS]--Function keys for batch processing
219 The setup of function keys for SAS batch processing
220 is unavoidably complex, but the usage of function keys is simple.
221 There are five distinct options:
223 Option 1 (default). Function keys in ESS[SAS] are not bound to elisp
224 commands. This is in accordance with the GNU Elisp Coding Standards
225 (GECS) which do not allow function keys to be bound so that they are
226 available to the user.
228 Options 2-5. Since GECS does not allow function keys to be bound by
229 modes, these keys are often unused. So, ESS[SAS] provides users with
230 the option of binding elisp commands to these keys. Users who are
231 familiar with SAS will, most likely, want to duplicate the function key
232 capabilities of the SAS Display Manager. There are four options (noted
237 SAS Display Manager has different function key definitions for
238 Unix (2, 4) and Windows (3, 5); ESS can use either.
240 The ESS[SAS] function key definitions can be active in all buffers
241 (global: 4, 5) or limited (local: 2, 3) only to buffers with files that
242 are associated with ESS[SAS] as specified in your auto-mode-alist.
245 The distinction between local and global is subtle. If you want the
246 ESS[SAS] definitions to work when you are in the *shell* buffer or when
247 editing files other than the file extensions that ESS[SAS] recognizes,
248 you will most likely want to use the global definitions. If you want
249 your function keys to understand SAS batch commands when you are editing
250 SAS files, and to behave normally when editing other files, then you
251 will choose the local definitions. The option can be chosen by the
252 person installing ESS for a site or by an individual.
256 For a site installation or an individual, uncomment ONLY ONE of the
257 following lines in your ess-site.el. ESS[SAS] Function keys are
258 available in ESS[SAS] if you uncomment either 2 or 3 and in all modes if
259 you uncomment 4 or 5:
261 ;;2; (setq ess-sas-local-unix-keys t)
262 ;;3; (setq ess-sas-local-pc-keys t)
263 ;;4; (setq ess-sas-global-unix-keys t)
264 ;;5; (setq ess-sas-global-pc-keys t)
267 The names -unix- and -pc- have nothing to do with the operating system
268 that you are running. Rather, they mimic the definitions that the SAS
269 Display Manager uses by default on those platforms.
272 If your site installation has configured the keys contrary to your
273 liking, then you must call the appropriate function.
275 (load "ess-site") ;; local-unix-keys
276 (ess-sas-global-pc-keys)
280 Finally, we get to what the function keys actually do. You may recognize
281 some of the nicknames as SAS Display Manager commands (they are in all
285 Unix PC Nickname "inferior" Alias (if any) and Description
288 revert the current buffer with the file of the same
289 name if the file is newer than the buffer
292 save the current .sas file (which is either the .sas
293 file in the current buffer or the .sas file associated
294 with the .lst or .log file in the current buffer) and
295 submit the file as a batch SAS job
298 switch buffer to .sas file
301 switch buffer to .log file, `refresh' and goto next
302 error message, if any
305 switch buffer to .lst file and `refresh'
308 switch buffer to filetype-1 (defaults to .txt) file
312 switch buffer to shell
315 open an interactive FSEDIT/FSBROWSE session on the SAS
319 toggle ESS[SAS] for .log files; may be useful for
320 certain debugging situations
323 switch buffer to filetype-2 (defaults to .dat) file
327 open a GSASFILE near point for viewing either in emacs
328 or with an external viewer
330 C-F1 C-F1 rtf-portrait
331 create an MS RTF portrait file from the current buffer
332 with a file extension of .rtf
334 C-F2 C-F2 rtf-landscape
335 create an MS RTF landscape file from the current buffer
336 with a file extension of .rtf
338 C-F3 C-F8 submit-region C-c C-r
339 write region to ess-temp.sas and submit
341 C-F5 C-F6 append-to-log
342 append ess-temp.log to the current .log file
344 C-F6 C-F7 append-to-output
345 append ess-temp.lst to the current .lst file
348 open an interactive INSIGHT session on the SAS
351 C-F10 C-F10 kill-em-all
352 kill all buffers associated with a .sas program
355 SUBMIT, PROGRAM, LOG and OUTPUT need no further explanation since
356 they mimic the SAS Display Manager function key definitions. However, six
357 other keys have been provided for convenience and are described below.
359 `shell' switches you to the *shell* buffer where you can interact with
360 your operating system. This is especially helpful if you would like to
361 kill a SAS batch job. You can specify a different buffer name to
362 associate with a SAS batch job (besides *shell*) with the buffer-local
363 variable ess-sas-shell-buffer. This allows you to have multiple
364 buffers running SAS batch jobs on multiple local/remote computers
365 that may rely on different methods specified by the buffer-local variable
366 ess-sas-submit-method.
368 F2 performs the `refresh' operation on the current buffer. `refresh'
369 compares the buffer's last modified date/time with the file's last
370 modified date/time and replaces the buffer with the file if the file is
371 newer. This is the same operation that is automatically performed when
372 LOG, OUTPUT, `filetype-1' or F11 are pressed.
374 `filetype-1' switches you to a file with the same file name as your .sas
375 file, but with a different extension (.txt by default) and performs
376 `refresh'. You can over-ride the default extension; for example in your
379 (setq ess-sas-suffix-1 "csv") ; for example
382 F9 will prompt you for the name of a permanent SAS dataset near point to
383 be opened for viewing by PROC FSEDIT. You can control the SAS batch
384 command-line with ess-sas-data-view-submit-options. For controlling the
385 SAS batch commands, you have the global variables
386 ess-sas-data-view-libname and ess-sas-data-view-fsview-command as well
387 as the buffer-local variable ess-sas-data-view-fsview-statement. If you
388 have your SAS LIBNAMEs defined in autoexec.sas, then the defaults for
389 these variables should be sufficient.
391 Similarly, C-F9 will prompt you for the name of a permanent SAS dataset
392 near point to be opened for viewing by PROC INSIGHT. You can control
393 the SAS batch command-line with ess-sas-data-view-submit-options. For
394 controlling the SAS batch commands, you have the global variables
395 ess-sas-data-view-libname and ess-sas-data-view-insight-command as well
396 as the buffer-local variable ess-sas-data-view-insight-statement.
398 F10 toggles ESS[SAS] mode for .log files which is off by default
399 (technically, it is SAS-log-mode, but it looks the same). The syntax
400 highlighting can be helpful in certain debugging situations, but large
401 .log files may take a long time to highlight.
403 F11 is the same as `filetype-1' except it is .dat by default.
405 F12 will prompt you for the name of a GSASFILE near the point in .log to
406 be opened for viewing either with emacs or with an external viewer.
407 Depending on your version of emacs and the operating system you are
408 using, emacs may support .gif and .jpg files internally. You may need
409 to change the following variables for your own situation.
410 ess-sas-graph-view-suffix-regexp is a regular expression of supported
411 file types defined via file name extensions.
412 ess-sas-graph-view-viewer-default is the default external viewer for
413 your platform. ess-sas-graph-view-viewer-alist is an alist of
414 exceptions to the default; i.e. file types and their associated
415 viewers which will be used rather than the default viewer.
417 (setq ess-sas-graph-view-suffix-regexp (concat "[.]\\([eE]?[pP][sS]\\|"
418 "[pP][dD][fF]\\|[gG][iI][fF]\\|[jJ][pP][eE]?[gG]\\|"
419 "[tT][iI][fF][fF]?\\)")) ;; default
420 (setq ess-sas-graph-view-viewer-default "kodakimg") ;; Windows default
421 (setq ess-sas-graph-view-viewer-default "sdtimage") ;; Solaris default
422 (setq ess-sas-graph-view-viewer-alist
423 '(("[eE]?[pP][sS]" . "gv") ("[pP][dD][fF]" . "acroread")) ;; default
426 C-F2 produces US landscape by default, however, it can produce A4
427 landscape (first line for "global" key mapping, second for "local"):
429 (global-set-key [(control f2)] 'ess-sas-rtf-a4-landscape)
430 (define-key sas-mode-local-map [(control f2)] 'ess-sas-rtf-a4-landscape)
434 @comment node-name, next, previous, up
435 @node iESS(SAS)--Interactive SAS processes, iESS(SAS)--Common problems, ESS(SAS)--Function keys for batch processing, ESS for SAS
436 @section iESS[SAS]--Interactive SAS processes
438 iESS (inferior ESS) is the method for interfacing with interactive
439 statistical processes (programs). iESS[SAS] is what is needed for
440 interactive SAS programming. iESS[SAS] works best
441 with the following settings for SAS command-line options
442 (the default of inferior-SAS-args):
445 -stdio -linesize 80 -noovp -nosyntaxcheck
450 required to make the redirection of stdio work
452 keeps output lines from folding on standard terminals
454 prevents error messages from printing 3 times
456 permits recovery after syntax errors
459 To start up iESS[SAS] mode, use:
464 The *SAS:1.log* buffer in ESStr mode corresponds to the file
465 myfile.log in SAS batch usage and to the "SAS: LOG" window in the SAS
466 Display Manager. All commands submitted to SAS, informative
467 messages, warnings, and errors appear here.
469 The *SAS:1.lst* buffer in ESSlst mode corresponds to the file
470 myfile.lst in SAS batch usage and to the "SAS: OUTPUT" window in the
471 SAS Display Manager. All data related printed output from the
472 PROCs appear in this window.
474 The iESS [SAS:1] buffer exists solely as a communications buffer.
475 Files are edited in the myfile.sas buffer. The C-c C-r key in
476 ESS[SAS] is the functional equivalent of bringing a file into the
477 "SAS: PROGRAM EDITOR" window followed by the 'Local' 'Submit' menu
478 commands. The user should never use this buffer directly.
480 For example, open the file you want to work with.
484 myfile.sas will be in ESS[SAS] mode. Edit as appropriate, and then start
485 up SAS with the cursor in the myfile.sas buffer.
489 Four buffers will appear on screen:
491 Buffer Mode Description
492 myfile.sas ESS[SAS] your source file
493 *SAS:1* iESS [SAS:1] ESS communication buffer
494 *SAS:1.log* Shell [] ESStr SAS log information
495 *SAS:1.lst* Shell [] ESSlst SAS listing information
497 If you would prefer each of the four buffers to appear in its
498 own individual frame, you can arrange for that. Place the
499 cursor in the buffer displaying myfile.sas. Enter the
504 The cursor will normally be in buffer myfile.sas.
505 If not, put it there:
509 Send regions, lines, or the entire file contents to SAS
510 (regions are most useful). A highlighted region will normally
511 begin with the keywords 'DATA' or 'PROC' and end with the
516 Information appears in the log buffer, analysis results in the
517 listing buffer. In case of errors, make the corrections in the
518 myfile.sas buffer and resubmit with another C-c C-r
520 At the end of the session you may save the log and listing
521 buffers with the usual C-x C-s commands. You will be prompted
522 for a file name. Typically, the names myfile.log and myfile.lst
523 will be used. You will almost certainly want to edit the saved
524 files before including them in a report. The files are
525 read-only by default. You can make them writable by the emacs
528 At the end of the session, the input file myfile.sas will
529 typically have been revised. You can save it. It can be used
530 later as the beginning of another iESS[SAS] session. It can
531 also be used as a batch input file to SAS.
533 The *SAS:1* buffer is strictly for ESS use. The user should
534 never need to read it or write to it. Refer to the .lst and
535 .log buffers for monitoring output!
537 @c DANGER Will Robinson!
540 @c - The ability to request help from a process for variables and
541 @c functions, and to have the results sent into a separate buffer.
542 @c - completion of object names and file names.
545 Troubleshooting: @xref{iESS(SAS)--Common problems}.
547 @comment node-name, next, previous, up
548 @node iESS(SAS)--Common problems, ESS(SAS)--Graphics, iESS(SAS)--Interactive SAS processes, ESS for SAS
549 @section iESS[SAS]--Common problems
552 1. iESS[SAS] does not work on Windows. In order to run SAS inside
553 an emacs buffer, it is necessary to start SAS with the -stdio option.
554 SAS does not support the -stdio option on Windows.
556 2. If M-x SAS gives errors upon startup, check the following:
557 - you are running Windows: see 1.
558 - ess-sas-sh-command (in the ESS source directory) needs to be
559 executable (solution: "chmod ugo+rx ess-sas-sh-command").
560 - sas isn't in your executable path (verify using "which sas" from
561 a shell command-line)
563 3. M-x SAS starts SAS Display Manager. Probably, the command "sas"
564 on your system calls a shell script. Specify the path to the real
565 "sas" executable in the file ess-sas-sh-command, i.e.:
567 /usr/local/sas612/sas </dev/tty 1>$stdout 2>$stderr $@@
569 To find the "sas" exectuable, you can execute the unix command:
571 find / -name sas -print
575 @comment node-name, next, previous, up
576 @node ESS(SAS)--Graphics, ESS(SAS)--MS Windows, iESS(SAS)--Common problems, ESS for SAS
577 @section ESS[SAS]--Graphics
579 Output from GPROCs can be displayed in a SAS/Graph window for SAS batch
580 on Windows or for both SAS batch and interactive with X11 on Unix. If
581 you need to create graphics files and view them with F12, then include
582 the following (either in myfile.sas or in your autoexec.sas):
584 filename gsasfile 'graphics.ps';
585 goptions device=ps gsfname=gsasfile gsfmode=append;
587 PROC PLOT graphs can be viewed in the listing buffer. You may
588 wish to control the vertical spacing to allow the entire plot
589 to be visible on screen, for example:
596 @comment node-name, next, previous, up
597 @node ESS(SAS)--MS Windows, , ESS(SAS)--Graphics, ESS for SAS
598 @section ESS[SAS]--MS Windows
602 iESS[SAS] does not work on Windows. @xref{iESS(SAS)--Common problems}.
605 ESS[SAS] mode for editing SAS language files works very well.
606 @xref{ESS(SAS)--Editing files}.
609 There are two execution options for SAS on Windows.
610 You can use batch. @xref{ESS(SAS)--Batch SAS processes}.
612 Or you can mark regions with the mouse and submit the code with
613 `submit-region' or paste them into SAS Display Manager.