If you are using xemacs you can use mmmmode to syntax highlight. I use ESS with statweave so as the first person answer why don't you use ESS to sybntax highlight and use statweave to do the work. I however do not use SAS but have used stata and R in the same file and they both work with their own syntax highlighting.
(require 'mmm-mode)
(require 'mmm-vars)
(setq mmm-global-mode 'maybe)
(setq mmm-submode-decoration-level 1)
(mmm-add-group
'latex-stats
'((r-tag
:submode r-mode
:face mmm-code-submode-face
:delimiter-mode nil
:front "begin{Rcode}"
:back "end{Rcode}"
:back-offset (backward-char -1)
:insert ((?R R-tag nil @ "\begin{Rcode}"
@ "\n" _ "\n" @ "\end{Rcode}" @))
)
(sta-tag
:submode STA-mode
:face mmm-code-submode-face
:delimiter-mode nil
:front "begin{Statacode}"
:back "end{Statacode}"
:back-offset (backward-char -1)
:insert ((?S STATA-tag nil @ "\begin{Statacode}"
@ "\n" _ "\n" @ "\end{Statacode}" @))
)))
(add-to-list 'mmm-mode-ext-classes-alist
'(nil "-swv.tex" latex-stats))
You just need to change to SAS-mode (I think if that is what it is called)
and I have in my latex.el file (loaded with a lambda in the init.el) the following
(local-set-key
[
(control f1)]
'(lambda ()
(interactive)
(if (string-match "\.tex" buffer-file-name)
(progn
(let (file-name file-name1 file-name-wihoutswv)
(setq file-name (buffer-file-name))
(setq file-name1 (file-name-nondirectory file-name))
(setq file-name-wihoutswv (replace-regexp-in-string "-swv" ""
file-name1))
(setq file-name-wihoutswv (replace-regexp-in-string "\.tex" ""
file-name-wihoutswv))
(if (string-match "-swv\.tex" buffer-file-name)
(find-file-other-window (concat file-name-wihoutswv ".tex"))
(find-file-other-window (concat file-name-wihoutswv "-swv.tex"))
)
)
)
(message "You are in Latex-mode and this is neither swv nor TeX file. Cannot open corresponding tex or sweave file")
)))
and
(global-set-key [f1]
'(lambda ()
(interactive)
(save-buffer)
(if (string-match "-swv\.tex" buffer-file-name)
(progn
(interactive)
(latex-mode)
;;(font-lock-fontify-buffer)
(balance-windows)
(mylatex-delete-indent)
(save-buffer)
(save-window-excursion (run-current-statweave-file))
; (mylatex-clean)
)
(if (string-match "\.tex" buffer-file-name)
(progn
(interactive)
(latex-mode)
;(font-lock-fontify-buffer)
(balance-windows)
(do-pdf)
; (mylatex-clean)
)
(message "this is not either TeX nor SWV file and I don't know what to do other than saving the buffer to the file. So I did")
))
)
)
(defun run-current-statweave-file ()
"Execute statweave on a -swv.tex file and launch evince to view output"
(interactive)
(let (file-name file-name1 file-name-wihoutswv cmd1-str cmd2-str status)
(setq file-name (buffer-file-name))
(setq file-name1 (file-name-nondirectory file-name))
(setq file-name-wihoutswv (replace-regexp-in-string "-swv\.tex" ".pdf" file-name1))
;; (setq cmd1-str (concat "statweave " file-name1 " && evince " file-name-wihoutswv " &" ))
(setq cmd1-str (concat "statweave " file-name1 ))
(setq cmd2-str (concat "evince " file-name-wihoutswv " &"))
;; (shell-command cmd1-str)
(setq output-buffer "swvoutput")
(save-window-excursion (setq status (shell-command cmd1-str output-buffer)))
;;(message status)
;; (let (status) ((shell-command cmd1-str output-buffer)))))
))
It looks awful and I am not an lisp expert so I am sure it has a lot of inefficiencies but it works.