Hi everyone,
I am trying to run python code in SAS Viya using proc fcmp. However the output is not getting displayed.
I am using the code from the following link :
https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lecompobjref/p18qp136f91aaqn1h54v3b6pkant.htm
proc fcmp;
declare object py(python);
submit into py;
def MyFunc(arg1):
"Output: MyKey"
#This is a comment
ReturnVar = arg1 * 5 #This is another comment
return ReturnVar
endsubmit;
rc = py.publish();
rc = py.call("MyFunc", 10);
x = py.results["MyKey"];
put x=;
run;
Have attached screenshot of the result below for your reference.
Thanks and regards,
Mohammad Umair Kazi
Proc FCMP is "putting" texts/outputs into the Listing ODS, and SAS Studio seems not to have one. 🙂
Try to add:
filename t temp;
proc printto print=t;
run;
before the proc FCMP and then add:
proc printto;
run;
data _null_;
infile t;
input;
put _infile_;
run;
filename t;
after the proc FCMP. And look into the log.
Bart
Proc FCMP is "putting" texts/outputs into the Listing ODS, and SAS Studio seems not to have one. 🙂
Try to add:
filename t temp;
proc printto print=t;
run;
before the proc FCMP and then add:
proc printto;
run;
data _null_;
infile t;
input;
put _infile_;
run;
filename t;
after the proc FCMP. And look into the log.
Bart
Bart is correct. A variation you might try is to create a SAS function that returns the Python function’s value instead of PROC FCMP writing it to an output destination. To do this I added the following:
options set=MAS_PYPATH="point-to-your-python.exe"
set=MAS_M2PATH "point-to-your-mas2py.py"
cmplib=work.fcmp;
proc fcmp outlib=work.fcmp.pyfuncs;
function TimesFive(SASArg);
declare object py(python('MySASFunc'));
submit into py;
def MyFunc(arg1):
"Output: MyKey"
#This is a comment
ReturnVar = arg1 * 5 #This is another comment
return ReturnVar
endsubmit;
rc = py.publish();
rc = py.call("MyFunc", SASArg);
x = py.results["MyKey"];
return(x);
endsub;
run;
data test;
x=5;
y=TimesFive(x);
run;
Output:
X Y
5 25
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.