Hello,
I'm trying to use python inside a proc fcmp. I configure the sascfg_personal.py to use winiomwin but when the session is starting present the follow error message:
ERROR: Micro Analytic Service failed to execute method
ERROR: Python execution: Traceback (most recent call last): File "E:\SAS\SASHome\SASFoundation\9.4\tkmas\sasmisc\mas2py.py", line
394, in execute out = up[1].get(func)[0](up[0])(*parms) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File
"C:\Users\sasdemo\AppData\Local\Temp\tmplfbeub0i\py.py", line 5, in sasReadWrite sas = saspy.SASsession('E:\Program
Files\Python311\Lib\site-packages\saspy\sascfg_personal.py') ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^TypeError: SASsession.__init__()
takes 1 positional argument but 2 were given
Here is the SAS code
proc fcmp;
length workpath outfile $ 500;
workpath = pathname('work');
file log;
declare object py(python);
submit into py;
def sasReadWrite(workpath):
"""Output: output_table"""
import pandas as pd
import saspy;
sas = saspy.SASsession('E:\Program Files\Python311\Lib\site-packages\saspy\sascfg_personal.py')
ds = sas.sasdata(table='AIR', libref='SASHELP')
df_from_sd = ds.to_df()
sas.saslib(libref='out', path = workpath)
outds = sas.dataframe2sasdata(
df = df_from_sd,
libref = 'out',
table = 'final',
encode_errors = 'replace'
)
sas.endsas()
return outds.table
endsubmit;
rc = py.publish();
rc = py.call('sasReadWrite', workpath);
outfile = py.results['output_table'];
if not missing(outfile) then
put 'Output dataset:' outfile;
run;
proc print data=final(obs=10);
run;
I can't speak to your overall workflow, but the error you're getting is because you need the keyword for that value: cfgfile=
sas = saspy.SASsession(cfgfile='E:\Program Files\Python311\Lib\site-packages\saspy\sascfg_personal.py')
All parameters for SASsession are keyword, not positional. So, that should get rid of this error.
Tom
Hey Tom,
In my sascfg_personal.py the SAS Config Name = winiomwin. Should i change the cfgfile value to winiomwin. ?
Have you tried using SASPy outside of proc fcmp, so you can figure out how it works and see if what you are doing is correct? Trying to figure out what's wrong from running inside of proc fcmp isn't going to work. cfgfile is the path of the config file you want to use, when you don't simply have it in any of the search paths where it would already be found. cfgname is the name of a config definition in that file (python Dict with config values). So, no, that wouldn't make sense. You're just running this with a local SAS install on your PC? Just run Python and SASPy there outside of SAS to get a connection and see that what you're trying to do is correct.
Did you get this working? Was that syntax error the only issue?
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.