This package provides interface to SAS through saspy
and reticulate
.
Prerequisites
To use sasr
, you need to make sure you have the following
- An SAS server that is accessible from the machine that you want to run
sasr
on - The machine that you want to run
sasr
has Python and Java
Installation
To install sasr
, please use the following command
remotes::install_github(repo = 'insightsengineering/sasr')
Reticulate will be installed automatically, but Python package saspy
will not.
If you do not have Python, you can use the following code to install Python, or it can be installed automatically after you call some python related stuffs.
library(reticulate)
install_python()
To install saspy
, use the following code
library(sasr)
install_saspy()
After the installation completes, you are ready to use sasr
package.
Short Tutorial
To use sasr
, you need to follow these steps
- Configure your SAS server in
sascfg_personal.py
under your working directory or the home directory. This is the default file thatsasr
will look at. However, you can still change that throughoptions(sascfg = )
, thensasr
will try to find any name that is available in your specified option.- If you don’t know how to create this file, use
sascfg()
to create the file. Required arguments includehost
andsaspath
.-
sascfg()
only creates ssh based SAS session. - Only password-less ssh connection is supported, e.g. ssh via public keys.
-
host
is the hostname of the SAS server. -
saspath
is the SAS executable path on the SAS server. - Other arguments are added to the configuration file directly.
-
tunnel
andrtunnel
are required if you want to transfer datasets between R and SAS. Use integers liketunnel = 9999L
in R, or modifysascfg_personal.py
to make sure they are integers.
-
- You can create the configuration by yourself and then SAS connection will not be restricted to ssh.
- You can have multiple configuration files with different file names
- If you don’t know how to create this file, use
- Create the SAS session based on the configuration file
- To use the default connection specified in the configuration file, you can run any command like
run_sas
,df2sd
orsd2df
.- The session will be created if there is no session available stored in
.sasr_env$.sas_session
- If
.sasr_env$.sas_session
is created, this session will be used by default. - Do not create any variable called
.sas_session
in environmentsasr:::.sasr_env
- The session will be created if there is no session available stored in
- To create the session manually, you can call
sas_session_ssh()
-
SAS_session
have one argumentsascfg
, pointing to the SAS session configuration file.
-
- To use multiple sessions, you need to store the session
your_session <- sas_session_ssh(sascfg)
- To use the default connection specified in the configuration file, you can run any command like
- Transfer the datasets from R to SAS using
df2sd
- Tunneling must be enabled to transfer datasets.
- The variable names of the datasets should not contain dots otherwise SAS may not recognize.
- The index (row names) will not be transferred to SAS.
- Use
run_sas
to submit SAS code to the SAS server.- The returned value is a named list,
LST
is the result andLOG
is the log file -
run_sas
has argumentresults=
, it can be either “TEXT” or “HTML”. This argument decides the LST format.
- The returned value is a named list,
- Transfer SAS datasets back to R use
sd2df
FAQ
Q: Why use saspy
instead of using ssh
tunnels?
A: Although we can use ssh
tunnels to transfer data and execute SAS commands, there are many restrictions: it only supports ssh
connection. Using saspy
, the official Python interface to SAS, we can enable all connection types, without reinventing the wheel, e.g. we can also connect to a local SAS installation with the same syntax, or connect to a remote SAS Viya through http
. In addition, SAS sessions in saspy
will not end until you terminate it (or encounter net work issues), it will be nice to execute multiple SAS code one by one, not necessarily putting them in one script and execute the whole script at once. Also, with the update of saspy
over time, sasr
will be easily extensible, to include functionalities other than transferring data and executing SAS code.