/sas-mode

sas mode for emacs

Primary LanguageEmacs LispGNU General Public License v3.0GPL-3.0

sas.el a sas mode for emacs

sas mode for emacs

Installation

  1. Download (or clone) sas.el and put it in your emacs directory (for example the directory /home/foouser/.emacs.d/lisp)
  2. To use SAS as another babel language, add the following to your .emacs
    (load "/home/foouser/.emacs.d/lisp/sas.el")
    (require 'sas)
        

    If you use ESS (for R) and sas you should disable the automatic loading of SAS-mode from ESS and load sas after:

    (require 'ess)
    (setq auto-mode-alist (delete '("\\.[Ss][Aa][Ss]\\'" . SAS-mode) auto-mode-alist))
    (load "/home/foouser/.emacs.d/lisp/sas.el")
    (require 'sas)
        

Philosophy

ESS does not update SAS-mode anymore. To have syntaxic coloration, session (as in python-mode) and keyboard shortcuts as in elpy or ESS, I have made a compilation of these sources into this sas.el. It could be used with ob-sas.el to make sas src block in org mode files. As I don’t have windows I don’t know if it works on windows.

Examples

  1. Start sas

    In a file with sas mode enabled, start SAS with run-sas (M-x run-sas)

  2. Submit commands

    sas comes with several shortcuts to submit sas commands

    (defvar sas-mode-map
     (let ((map (make-sparse-keymap)))
       (define-key map "\C-c\C-r"   #'sas-shell-send-region)
       (define-key map "\C-c\C-b"   #'sas-shell-send-buffer)
       (define-key map "\C-c\C-j"   #'sas-shell-send-line)
       (define-key map [(control return)] #'sas-shell-send-dwim)
       (define-key map "\C-c\C-v"   #'sas-view-table)
       (define-key map "\C-c\C-q"   #'sas-exit)
       map)
     "Keymap for `sas-mode'.")
        
    • For instance a C-RET control-return (sas-shell-send-dwim) in a middle of a data step or a proc step will send the whole data step or proc step to SAS.
    • C-c C-v (sas-view-table) when point is on a SAS data-table print the first three lines (customize sas-view-maxnumber-of-rows variable to change the number of displayed rows). For users who prefer proc fsview sas-fsview-table or sas-fsview-edit-table can be used instead.
    • C-c C-q will close the SAS buffers

Config

  • The custom variable sas-shell-interpreter is sas but it can be useful to point to another sas executable.
  • The custom sas-sas-windows can be set to t if SAS windows is used
  • The custom sas-realsession can be set to nil on windows in order to create a temporary user library and submit SAS region using SAS batch mechanism.
  • For doom emacs

    the following code in config.el

    ;; to disable ESS SAS-mode
    (after! ess
    (setq auto-mode-alist (delete '("\\.[Ss][Aa][Ss]\\'" . SAS-mode) auto-mode-alist)))
    ;; sas-mode using sas.el
    (use-package sas)
    (after! sas
      (map! :map sas-mode-map
         :localleader
         "RET" #'sas-shell-send-dwim
         "r" #'sas-shell-send-region
         "j" #'sas-shell-send-line
         "v" #'sas-view-table
         "q" #'sas-exit
         "b" #'sas-shell-send-buffer))
        

    and the classical loading mechanism in package.el

    (package! sas
      :recipe (:host github :repo "Pierre-Andre/sas-mode"))
        

    should work.

  • For windows user sas-sas-windows must be set to non-nil and sas-realsession must be set to nil, for instance using the following code in .emacs
    ;; to disable ESS SAS-mode
    (require 'ess)
    (setq auto-mode-alist (delete '("\\.[Ss][Aa][Ss]\\'" . SAS-mode) auto-mode-alist))
    ;; sas-mode using sas.el
    (load "/home/foouser/.emacs.d/lisp/sas.el")
    (require 'sas)
    (setq sas-sas-windows 't sas-realsession nil)