How to run SAS programs in Jupyter Notebook

28

We've just celebrated Earth Day, but I'm here to talk about Jupyter -- and the SAS open source project that opens the door for more learning. With this new project on the github.com/sassoftware page, SAS contributes new support for running SAS from within Jupyter Notebooks -- a popular browser-based environment used by professors and data scientists.

My colleague Amy Peters announced this during a SAS Tech Talk show at SAS Global Forum 2016. If you want to learn more about Jupyter and see the SAS support in action, then you can watch the video here.

Visit the project on GitHub: sas_kernel by sassoftware

Within Jupyter, the sas_kernel provides multiple ways to access SAS programming methods. The most natural method is to create a new SAS notebook, available from the New menu in the Jupyter Home window and from the File menu in an active notebook:

newsasnotebook
From a SAS notebook, you can enter and run SAS code directly from a cell:

sasnotebook
There is even a Notebook extension (./nbextensions/showSASLog) that can show you the SAS log.

The second way that you can run SAS code is by using special Jupyter "magics" supported by the sas_kernel. These magic commands look almost just like SAS macro calls (imagine that!). From within a Python language notebook, you can inject your SAS program code and pull in SAS results. This allows you to move easily between Python and SAS in a single environment. Here's a simple example:

%%SAS
proc means data=sashelp.cars;
run;
ods graphics / height=500 width=800;
proc sgplot data=sashelp.cars;
histogram msrp;
run;

How to get started


Update 25July2016: Support for Jupyter is now part of the SAS University Edition! See the SAS University Edition documentation for information about how to use it.


In SAS environments outside of SAS University Edition, here's what you need to run SAS with Jupyter:

  • SAS 9.4 or later running on Windows, Linux, or even z/OS (see support for SASPy, the underlying package)
  • Python 3 installed on the same machine (that's basically part of Linux)
  • Access to the OS shell to install/configure the Jupyter Notebook infrastructure and the sas_kernel.

End users of Jupyter Notebook do not need special privileges. And you can access it from a browser on any system: Windows, Mac, Linux...whatever. In the SAS Tech Talk video with Amy, we were running on my Windows laptop using Chrome, connecting to a Linux instance of Jupyter and SAS. The GitHub project has all of the doc and step-by-step instructions for installation.

What's next for SAS and Jupyter?

This is just the start for SAS in the Jupyter world. Amy says that she has already received lots of interest and feedback, and SAS is working to make the Jupyter Notebook approach available in something like SAS University Edition and SAS OnDemand for Academics. Stay tuned!

Share

About Author

Chris Hemedinger

Senior Manager, SAS Online Communities

+Chris Hemedinger is the manager of SAS Online Communities. He's also co-author of the popular SAS for Dummies book, author of Custom Tasks for SAS Enterprise Guide using Microsoft .NET, and a frequent participant on the SAS Enterprise Guide discussion forum.

Related Posts

28 Comments

  1. I wonder if there will be any possibility (some sort of add-inns or upgrade) in a way that the same job can be done by SAS 9.3.

    • Chris Hemedinger
      Chris Hemedinger on

      I think we heard this request several times at SAS Global Forum. I know that Windows support is under consideration; I don't know the timetable.

    • I want to second the motion to make this work on windows. On a lark I googled "sas kernal jupyter notebook" and found this recent announcement. I am very excited. I use python + jupyter to memorialize my work ("ask the data questions and write down the answers") and have been wishing for the same thing with SAS.

      • Chris Hemedinger
        Chris Hemedinger on

        Hi Will, nothing to share yet. I did have a conversation with the developers last week, and they were looking into an approach...but it's premature to say when it will happen.

  2. The Linux requirement is a bit odd, since the Jupyter kernel could control SAS on Windows via the .NET interface using pywin32 or a similar module. I'll have to look at the source to see how the kernel connects to SAS.

    • Chris Hemedinger
      Chris Hemedinger on

      I think the team worked on Linux first, as that's a popular multi-user SAS platform where Jupyter can have a positive impact on teams. And also the SAS University Edition is delivered with a packaged Linux VM, so this will be a natural fit...eventually. I think Windows support is inevitable, just wasn't the focus right out of the gate. I suspect the mechanism will need to be a little different for Windows.

    • Chris Hemedinger
      Chris Hemedinger on

      Hi Bjorn, I'd guess the answer is Yes, on a technical level. However, SDD has some pretty strict auditing/authentication/process requirements, so I'm not sure if it's fit for the purpose. If you're working with a SAS-hosted SDD environment, it might be worth asking your SAS rep about this possibility.

  3. Pingback: Choose your own adventure with SAS Viya - SAS Users

  4. Pingback: Reproducible research: Is my SAS code enough? - A Shot in the Arm

  5. How does this work if I have SAS grid and Jupyter is on remote server? In short, if I have server based environments as opposed to SAS and Jupyter software on my pc?

    • Chris Hemedinger
      Chris Hemedinger on

      Hi Kevin, great question. I think that the way this works right now it doesn't play into the Grid environment. That is, you have Jupyter hosted on a single node where you have SAS available, and it launches/communicates with a single SAS process. I'll ping the developer (Jared) to see if he has anything to add about this.

    • Jared Dean

      Kevin,
      Currently the SAS Kernel can't take advantage of SAS Grid. Other organizations have groups connecting to grid nodes directly through SSH which allows a centralized Jupyter server that is located apart from SAS. You can see setup details from the inline comments here: https://github.com/sassoftware/saspy/blob/master/saspy/sascfg.py

      If SAS Grid and Jupyter interaction is a strong business need, I would encourage you to enter an issue at https://github.com/sassoftware/sas_kernel/issues

  6. Pingback: Using Jupyter and SAS together with SAS University Edition - The SAS Dummy

  7. Pingback: Reporting on GitHub accounts with SAS - The SAS Dummy

  8. Pingback: A journey of SAS high performance - SAS Users

  9. Pingback: Reproducible research: Is my SAS code enough? - SAS Voices

  10. Chris, I currently teach a Statistical Computing course using SAS, I migrated myself and my students over to using SAS EG as a programming interface, but I am wondering if this is the best way to go? Do you have a sense of what is being used as the programming interface in industry?

    Should I be switching to a notebook approach, or is SAS studio a better way to go?

    I have multiple courses I teach and I will be developing a first course for a new Data Science masters that uses SAS and I wonder if I should be using SAS-EG, SAS Studio or learning these notebooks? I have noticed that workflow is something students need to learn, instead of figuring it out over the years and that the programming interface has an impact on learning and I wanted to get a sense of which method to use as I go forward.

    Thanks.

    Laura

Leave A Reply

Back to Top