Thanks to the SAS blog (https://blogs.sas.com/content/sasdummy/2016/04/24/how-to-run-sas-programs-in-jupyter-notebook/), I'm trying to use SAS in Jupyter Notebook. But I would like to know how I can recall and run another SAS code file in Jupyter Notebook.
Back in my Windows SAS, I always have the below line at the beginning of all my code files.
%include ".\1. Research\MacroSetup.sas";
Please note that I used a relative path in %include statement, so it starts with "."
I wanted to achieve the same thing in Jupyter, but it didn't work. Could anybody please help me with that? Even though I would like to keep using the relative path, it is not necessary. So I replaced it with its full path, but it didn't work.
In addition, I also replaced "\" with "\\" in Jupyter, but it didn't work.
The log I got is here:
Error in calling magic 'include' on line: [Errno 22] Invalid argument: 'C:\\Dropbox (Personal)\\1. Research\\0 Common sets\\Compustat\\.\x01' args: ['.\x01. Research\\MacroSetup.sas ;'] kwargs: {} Traceback (most recent call last): File "C:\Users\yjaey\Anaconda3\lib\site-packages\metakernel\magic.py", line 94, in call_magic func(*args, **kwargs) File "C:\Users\yjaey\Anaconda3\lib\site-packages\metakernel\magics\include_magic.py", line 30, in line_include text += open(filename).read() + "\n" OSError: [Errno 22] Invalid argument: 'C:\\Dropbox (Personal)\\1. Research\\0 Common sets\\Compustat\\.\x01' %include FILENAME ... - include code from filename into this code This line magic will get the contents of a file and include it in this cell evaluation. You can have multiple %include's at the beginning of a cell, and they will be included in order. Examples: %include myprog.py %include myprog1.py myprog2.py
In addition to this macro setup, many of my SAS codes are inter-related with %include statement. so, I really would like to figure this out. Many thanks.
Jupyter is always sensitive for '%',
If you need to run a SAS macro as the first statement, then insert a blank line as the first line in the notebook cell and the macro on the second line. The blank line prevents Python from interpreting the macro variable as a magic.
I'm not sure what exactly you want to achieve by running another ipynb file,
but I guess it should be executed like this:
%run ./another_file.ipynb
foo()
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.