SAS Micro Analytic Service
1.3 supports modules that are written in the Python programming language.
A Python module represents a single Python script. Python modules
can be published and called from DS2 (see
DS2 Interface to Python). If your SAS solution supports it,
Python modules can be published and called directly through the SAS
Micro Analytic Service Java interface. To use Python modules directly
from the Java interface:
-
Use a value of SF_PYTHON_MODULE
when calling newModuleContext() to create a new Module Context.
Sasdsmas mas = new tksfjni(numServerThreads,
logCfgLocation);;
// Create module context
long moduleCtx = mas.moduleCtx(userCtx, Language.PYTHON,
"My_Moudle_Name", null);
-
Call sfNewRevision(),
and use the Python script code and an array of strings containing
the parameter names.
Note: The order of the parameter
names is important. Match the order in which the parameters were set
in the symbol table that is sent to the Execute method. This matching
is needed in order to send parameter values between SAS Micro Analytic
Service and Python.
// Create new Revision
int rev = mas.newRevision(moduleCtx, pythonCode,
"My_Moudle_Name", paramNames, null);
-
Call execute() to execute
the Python script, using the symbol table containing the input values.
tksfValues symbolTable = new tksfValues(numOfParameters, numInputs);
… (fill in symbol table with both input and output parameters)
int rc = mas.execute(userCtx, moduleCtx, 0, null, symbolTable);
Missing input values
are translated to NONE in Python. To indicate a missing output value,
set the variables value to NONE within your Python script.