Hello, I am new to using Python. I developed a SAS program using Enterprise Guide on my windows devise. I would like to execute this program via a notebook in Jupyter Lab using Python 3.5.2. The notebook is running on a linux server.
I uploaded my .sas file to the linux server of the Jupyter notebook. I can successfully connect and create a SAS session on our Grid environment. The SAS session runs on a linux server. After installing and importing SASPY I try to submit the SAS script/file as follows:
sas.submit('/users/myuserid/files/SAS_filename.sas')
The program starts and runs for a while. It successfully creates librefs, then after the first data step I get this error:
3 The SAS System 08:16 Tuesday, October 29, 2019 21 ods listing close;ods html5 (id=saspy_internal) file=_tomods1 options(bitmap_mode='inline') device=svg style=HTMLBlue; 21 ! ods graphics on / outputfmt=png; NOTE: Writing HTML5(SASPY_INTERNAL) Body file: _TOMODS1 22 ;*';*";*/; 23 /user/myuserid/files/SAS_filename.sas _ 180 ERROR 180-322: Statement is not valid or it is used out of proper order.
I am not sure what this means or where to start with this. None of the ODS code is in my program. Any ideas as to what is happening here?
See the SASPy API Reference
https://sassoftware.github.io/saspy/api.html#saspy.SASsession.submit
Using %include as Tom suggests would presume that Jupyter, where you said you uploaded the code, is the same machine where you are submitting to SAS.
Two additional options you have:
1. Ditch the .sas file and put it's contents directly into your notebook as such:
results_dict = sas.submit( """ libname tera teradata server=teracop1 user=user pw=pw; proc print data=tera.dsname (obs=10); run; """ )
2. Read the file contents into Python and then submit:
code = open('/users/myuserid.files/SAS_filename.sas').read() results_dict = sas.submit(code)
From the log snippet you posted it looks like SASpy is considering the string you gave as the actual SAS code to run. Not the name of a file. So just change it to a valid SAS command. Like:
sas.submit('%include "/users/myuserid/files/SAS_filename.sas";')
See the SASPy API Reference
https://sassoftware.github.io/saspy/api.html#saspy.SASsession.submit
Using %include as Tom suggests would presume that Jupyter, where you said you uploaded the code, is the same machine where you are submitting to SAS.
Two additional options you have:
1. Ditch the .sas file and put it's contents directly into your notebook as such:
results_dict = sas.submit( """ libname tera teradata server=teracop1 user=user pw=pw; proc print data=tera.dsname (obs=10); run; """ )
2. Read the file contents into Python and then submit:
code = open('/users/myuserid.files/SAS_filename.sas').read() results_dict = sas.submit(code)
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.