Dear orgmode users
as the best way to submit a Babel support for a new language is this
mailing list, I submit this partial support for SAS
language (using ESS).
This is partial as only few header arguments are supported
:results output
:output graphics
:session
arguments are supported but one of the most important, :output value, is
not supported (as I am not able to figure out what does it really mean
with SAS).
I am not proud of it but I have added a
:results odsgraphics
for odsgraphics (which are different from sas/graph classical graphics).
If someone is interested in that support, please see the attached file
(as I don't actually know anything about the orgmode mailing list
policy about attached file, I hope it will be still attached...)
Comments and suggestions are welcome.
Best regards
Pierre-Andre
;;; ob-sas.el --- org-babel functions for sas code evaluation
;; Copyright (C) 2017 P.A. Cornillon
;; Author: P.A. Cornillon
;; G. Jay Kerns
;; Eric Schulte
;; Dan Davison
;; This file is not part of GNU Emacs.
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
;;; Commentary:
;; The file provides Org-Babel support for evaluating sas code. It is
;; basically result of find-and-replace "sas" for "julia" in
;; ob-julia.el by G. Jay Kerns.
;; 1) Parameter ":results output" needs a
;; to give the right filename for SAS in the Parameter ":results value"
;; does not work (I'm not sure it makes sense or is useful). Parameter
;; ":session" works with default value using ESS
;;
;;; Requirements:
;; Sas: http://sas.com
;; ESS: http://ess.r-project.org
;;; Code:
(require 'ob)
(require 'cl-lib)
(declare-function orgtbl-to-csv "org-table" (table params))
(declare-function sas "ext:ess-sas" ( start-args))
(declare-function inferior-ess-send-string "ext:ess-inf" ())
(declare-function ess-make-buffer-current "ext:ess-inf" ())
(declare-function ess-eval-buffer "ext:ess-inf" (vis))
(declare-function org-number-sequence "org-compat" (from to inc))
could be useful to increase or decrease timeout
(defcustom org-babel-sas-timeout 1000
"Timeout (in sec) used when waiting output from a submitted src block (to sas) with argument :session."
:group 'org-babel
:type 'integer)
could be useful to tweak printing page size
(defcustom org-babel-sas-print-options "options formdlim='' pagesize=max;\n"
"general options used to have the maximum page size"
:group 'org-babel
:type 'string)
where is SAS
(defcustom org-babel-sas-command "/usr/local/bin/sas_u8"
; inferior-SAS-program-name
"Name of command to use for executing sas code."
:group 'org-babel
:type 'string)
;;;
(defvar org-babel-sas-lepoint 1)
(defvar org-babel-sas-logfile-name "log_sas.log")
(defvar org-babel-sas-eoe-indicator "data eoe_org_data;\n nbabelvareoe=1;\nrun;\nOPTIONS NODATE NONUMBER;\nTITLE1;\nTITLE2;\nproc print data=eoe_org_data;\nrun;")
(defvar org-babel-sas-eoe-output "Obs.nbabelvareoe\n\n1 1")
(defvar org-babel-sas-boe-output "$ tty\n/dev/pts/[0-9]+\n\\$")
(defconst org-babel-header-args:sas
'((hsize . :any)
(vsize . :any)
(xpixels . :any)
(ypixels . :any)
(border . :any)
(width . :any)
(height . :any)
(results . ((file list vector table scalar verbatim)
(raw org html latex code pp wrap)
(replace silent append prepend)
;; NOTE: not sure 'value' makes sense in sas
;; we may want to remove it from the list
(output graphics
"sas-specific header arguments.")
(add-to-list 'org-babel-tangle-lang-exts '("sas" . "sas"))
;; session using ESS is the way to go, so make that the default
(defvar org-babel-default-header-args:sas '((:results . "output") (:session . nil)))
;; trim white space and garbage
(defun org-babel-sas-trim-white (s)
"replace S by empty string if S is whitespace only"
(if (string-match "\\`[ \t\n\r]+\\'" s)
(replace-match "" t t s)
s))
;; let's go: main function
(defun org-babel-execute:sas (body params)
"Execute a block of sas code.
This function is called by `org-babel-execute-src-block'."
(save-excursion
(let* ((result-params (cdr (assq :result-params