Perhaps you have already encountered situations where you have a program written in python (there can be many such programs and they can be written by your colleagues) and you need to embed this launch into the SAS program code.
How to do it?
So, for this we will use the following open-source tool with
github . First, let's copy the SASJavaExec.java file to ourselves and compile it into a jar file. Important point: it is necessary to compile using JDK 1.7_025, since When using JDK 1.8, an error will occur in the SAS code.
')
1. Create classes: java -jar SASJavaExec.jar
2. Compile to jar file: jar cfm SASJavaExec.jar manifest.txt SASJavaExec $ 1.class SASJavaExec.class
Where manifest.txt is a single-line file: Main-Class: SASJavaExec. Now we have a SASJavaExec.jar file.
Next you need to register it in the system settings. I ran the program on Windows, so in the environment settings I need to set the CLASSPATH variable.
In my case, it looked like this:
More details on how to do this can be found
here .
After you have done all the steps above, run SAS.
You must register the following paths:
Path to the python file:% let PYTHON_EXEC_COMMAND = C: \ Python27 \ python.exe;
Path to your python program:
%let WORK_DIR = C:\SAS\T_Java\Example; python_pgm = "&WORK_DIR.\digitsdata_svm.py";
After that we write the executable code - Data set:
data _null_; length rtn_val 8; *** Python program takes working directory as first argument; python_pgm = "&WORK_DIR.\digitsdata_svm.py"; python_arg1 = "&WORK_DIR"; python_call = cat('"', trim(python_pgm), '" "', trim(python_arg1), '"'); put python_pgm = ; put python_arg1 =; put python_call=; declare javaobj j("SASJavaExec", "&PYTHON_EXEC_COMMAND", python_call); j.callIntMethod("executeProcess", rtn_val); run;
Next, run our program and look at the execution log:
python_pgm=C:\SAS\T_Java\Example\digitsdata_svm.py python_arg1=C:\SAS\T_Java\Example python_call="C:\SAS\T_Java\Example\digitsdata_svm.py" "C:\SAS\T_Java\Example" 27, 2016 6:36:39 AM SASJavaExec executeProcess INFO: Executing [C:\Python27\python.exe, C:\SAS\T_Java\Example\digitsdata_svm.py, C:\SAS\T_Java\Example] ... 27, 2016 6:36:39 AM SASJavaExec executeProcess INFO: Starting external process ... 27, 2016 6:36:39 AM SASJavaExec executeProcess INFO: External process exit value 0.
All right, the digitsdata_svm.py program runs from SAS.
I hope this article was useful for you.
PS An example of the SAS program itself was also taken with github a link to which was indicated at the beginning of the article.