SAS notebooks
Overview
SAS notebooks are available for researchers who are more comfortable using SAS and its ecosystem. These are built off the same base image as python notebooks, but include the official SASPy library to allow for the execution of SAS in a notebook environment.
Working with SAS a notebook environment is slightly different than the SAS desktop application, in that you need to utilize python to interchange data with SAS. This step is quite simple, and doesn't require any expertise in python. See working with tabular data below.
Enabling SAS notebooks
Because SAS is proprietary software, you will need to have a licensed version of SAS 9.4 in order to enable SAS notebooks on Redivis. Organizations can specify license information in their settings, which will make SAS notebooks available to all members of their organization. Alternatively, you can provide your own SAS license in your workspace.
Base image and dependencies
SAS notebooks are based off the python notebook base image, and can combine SAS with Python and optional python dependencies to create novel workflows.
To further customize your compute environment, you can specify various dependencies by Dependencies at the top-right of a notebook. Here you will see three tabs: Packages, pre_install.sh, and post_install.sh.
Use packages to specify the python packages you would like to install. When adding a new package, it will be pinned to the latest version of that package, but you can specify another version if preferred.
To manage system dependencies and for more complicated workflows, you can use the pre- and post- install shell scripts. These scripts are executed on either side of the python package installation, and are used to execute arbitrary code in the shell. For example, you can also use apt to install system packages (apt-get update && apt-get install -y <package>), or mamba to install from conda.
Working with tabular data
In order to load data into SAS, use a one-liner to pull any Redivis table or SQL query result, into a named SAS Data Set. All variable metadata will be loaded with the data.
Next, in a separate cell, use the %%SAS "magic" at the start of the cell to specify that this is SAS code.
Working with geospatial data
Loading geospatial data looks much the same as other tabular data, in that you can just call the .to_sas() method on any table or query in python. If that table or query result contains a geography variable, it is automatically be loaded as geospatial data to SAS via the mapimport proc.
In the uncommon case where your table has multiple variables of type geography, you'll need to explicitly specify which variable to use as the geography.
If you want to bypass the default behavior and load a table with a geography variable as a standard Stata table, you can explicitly set .to_stata(geography_variable = None).
Creating output tables
Redivis notebooks offer the ability to materialize notebook outputs as a new table node in a workflow. This table can then be processed by transforms, read into other notebooks, exported, or even re-imported into a dataset.
To create an output table, you must first save our SAS data set to a .sas7bdat file. You can then use the redivis.current_notebook().create_output_table() method in python to output your data.
If an output table for the notebook already exists, it will be overwritten by default. You can pass append=True to append, rather than overwrite, the table. In order for the append to succeed, all variables in the appended table that are also present in the existing table, must have the same type.
Storing files
As you perform your analysis, you may generate files and figures that are stored on the notebook's hard disk. There are two locations that you should write files to: /out for persistent storage, and /scratch for temporary storage.
Any files written to persistent storage will be available when the notebook is stopped, and will be restored to the same state when the notebook is run again. Alternatively, any files written to temporary storage will only exist for the duration of the current notebook session.
Last updated
Was this helpful?

