I'm trying to follow the documentation for using Python in Proc FCMP (in SAS 9.4). The following code is their example (link) of a basic Python function in Proc FCMP:
proc fcmp;
declare object py(python);
submit into py;
def PyProduct(var1, var2):
"Output: MyKey"
newvar = var1 * var2
return newvar,
endsubmit;
rc = py.publish();
rc = py.call("PyProduct", 5, 10);
MyResult = py.results["MyKey"];
put MyResult=;
run;
That code has an expected output of MyResult=50
, but when I run it nothing gets printed to the log. I get the following log file:
390 proc fcmp;
391 declare object py(python);
392 submit into py;
393 def PyProduct(var1, var2):
394 "Output: MyKey"
395 newvar = var1 * var2
396 return newvar,
397 endsubmit;
398 rc = py.publish();
399 rc = py.call("PyProduct", 5, 10);
400 MyResult = py.results["MyKey"];
401 put MyResult=;
402 run;
NOTE: PROCEDURE FCMP used (Total process time):
real time 1.17 seconds
cpu time 0.09 seconds
There is example code further down the same page (link) that works fine for me:
proc fcmp outlib=work.fcmp.pyfuncs;
function MyPyFunc(FCMParg);
declare object py(python);
submit into py;
def TimesFive(PythonArg):
"Output: MyKey"
newvar = PythonArg * 5
return newvar
endsubmit;
rc = py.publish();
rc = py.call("TimesFive",FCMParg);
MyFCMPResult = py.results["MyKey"];
return(MyFCMPResult);
endsub;
run;
options cmplib=work.fcmp;
data _null_;
x = MyPyFunc(5);
put x=;
run;
The second block of code correctly produces the expected output of x=25
in the log. This leads me to believe that Python, SAS, and the environment variables are set up correctly, so the issue must be somewhere within the code in the first block.
Why is the first code block not producing the output expected by the documentation?