sassoftware / saspy

A Python interface module to the SAS System. It works with Linux, Windows, and Mainframe SAS as well as with SAS in Viya.
https://sassoftware.github.io/saspy
Other
373 stars 150 forks source link

Cell magic `%%SAS` not found. #358

Closed ghost closed 3 years ago

ghost commented 3 years ago

I am getting this error - UsageError: Cell magic %%SAS not found when I run the following program on google colab -

%%SAS
proc print data=sashelp.class;
run;

But it works when i run the following program

from IPython.display import HTML
c = sas.submit("""proc print data=sashelp.class;
run;
""")
HTML(c['LST'])

I checked the issue on google and found need to load extension. Not sure what extension I need to load for SAS.

tomweber-sas commented 3 years ago

Ok, I got on colab and installed saspy and I do see the same thing. I don't know what kind of python environment colab is. Is it Jupyter. or just some other front end? That magic is specific to jupyter, so I guess this isn't that, since it didn't get installed. You don't really need that magic, You can just use the following instead of what you have above and it will do the same thing as the magic:

sas.submitLST("proc print data=sashelp.cars; run;", method='listorlog') 

That will render the LST if it exists else the LOG. Also, you don't need to use the ipython html for rendering html results, the SASsession object has that method for you, if you need it; just one other thing not needed to import.:

sas.HTML(c['LST'])
ghost commented 3 years ago

Thanks. It does not work in Jupyter as well if I just run the following command instead of creating sascfg_personal.py file -

sas = saspy.SASsession(java='C:\\Program Files (x86)\\Java\\jre1.8.0_221\\bin\\java.exe', iomhost=['odaws01-apse1.oda.sas.com','odaws02-apse1.oda.sas.com'], iomport=8591, encoding='utf-8')
sas

If I run the following command - it returns error "No SAS process attached. SAS process has terminated unexpectedly"

%%SAS
proc print data=sashelp.class;
run;

Again it works if i submit it in sas.submit( )

tomweber-sas commented 3 years ago

So, that magic creates it's own SAS session if you don't provide one. Since you haven't configured saspy to be able to connect, then when you try using it without providing a SASsession you already created (providing the correct configuration on the SASsession method), it fails to connect; that's the error you get in this scenario. You'd get the same error if you just submitted this since it's not configured.

sas = saspy.SASsession()

In your jupyter scenario, try this after creating your SAS session manually (of configure the config file then it'll all just work)

%%SAS sas
'sas code'

So, this is a different error than in colab. In colab there is no %%SAS (that's the error). In your jupyter you just aren't using it correctly; pass it a valid SASsession, or configure saspy so it can connect when you use it since you can't provide the configuration on the %%SAS itslef (error about SAS not attached/terminated).

I'm guessing colab isn't jupyter, just python w/ their own front end.

Tom