Working with SAS interactively #49
ryanzomorrodi
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi, I'm a grad student and I work with SAS and R for a lot my assignments. I really like using quarto to produce reports and unfortuntely there wasn't a great way to use SAS within quarto. A while back I came across
configSAS
, which introduced me to SASpy and has a roughknitr
engine for SAS.So I created a package to solve some of these issues. Only realizing that
sasr
existed after opening up the pkgdown site and seeing that View on CRAN had automatically been added because I had accidentally named it the same (I have since renamed it).Since I was primarily focused on quarto and my ambitions were never really to publish on CRAN, I implemented a few new ideas that I think would be cool for
sasr
to adopt:Knitr support
Seems like theres an issue and pull request for
knitr
support #39 #43.configSAS
implements aknitr
engine, but there's two major problems:I was able to solve both of these issues. (albeit with the somewhat janky solutions of adding a separate xml syntax highlighting file to render with and sticking the output within an iframe)
configSAS
To set up the quarto, use
sas_use_quarto()
.Output as HTML widget
I use SAS On Demand for Academics, and its quite annoying to have to go back and forth between On Demand and my IDE. I could try to run my code by sending it through saspy, but it generates html which I have to render each time and I also want to look at the logs when I run my code.
Solution:
sas_run_string()
, which not only runs your code, but outputs a widget with tabs for the output and logs. Since its a widget and not simply rendered html, it appears in the plots tab instead of viewer (at least in Positron), so you can keep your old output as you generate new output.Running SAS code with a keyboard shortcut
Getting widgets for the output is great, but it sounds tedious to wrap your sas code in an R string and use
sas_run_string()
a bunch of times. So I created the functionsas_run_selected()
, which uses the rstudio API to run whatever you have selected in SAS.Since we have the function, we can create a custom shortcut which allows us to run the code we selected without even typing in any R. This is my json for the shortcut in Positron
I assume its similar to what it would look like in RStudio, and I believe VSCode has a command that allows you to send selected text to the terminal so you can encapsulate the selected text in
sas_run_string()
and get the same shortcut for VSCode too.This all means you can use SAS interactively very similar to how you would for R or Python, and integrate them all into reports seamlessly.
Feel free to check out the repo or the docs for the package. I'd be willing to put in a few pull requests to add some of these features if you all are interested.
Note: everything was developed with SAS On Demand in mind. I'd be interested to see if the package functions work properly for other SAS Servers.
Beta Was this translation helpful? Give feedback.
All reactions