<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Execute Python code from a Base SAS program using Proc FCMP in SAS Community Nordic</title>
    <link>https://communities.sas.com/t5/SAS-Community-Nordic/Execute-Python-code-from-a-Base-SAS-program-using-Proc-FCMP/m-p/632951#M272</link>
    <description>&lt;P&gt;Did you know Base SAS can execute Python code? Starting with May 2019 release of SAS 9.4M6, the PROC FCMP procedure added support for submitting and executing functions written in Python from within a SAS session using the new Python object. Proc FCMP is where you create your own SAS functions, and this alone is a brilliant way of cleaning up your code. Now with 9.4M6 you can also execute python functions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It could look like this simple example below, and there are many good sources to study such as blogs and SAS Documentation (links below snippet).&lt;/P&gt;
&lt;P&gt;The necessary steps are these two and are performed where your SAS Foundation is installed:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Install Python&lt;/LI&gt;
&lt;LI&gt;Add two environment variables in Windows (read doc to learn steps needed for other OS such as linux)&lt;/LI&gt;
&lt;LI&gt;Start SAS and submit this code&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Many more examples in SAS Documentation and blog entries.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*  ENVIRONMENT VARIABLES 
  - MAS_M2PATH: C:\SAS\SASHome\SASFoundation\9.4\tkmas\sasmisc\mas2py.py 
  - MAS_PYPATH: C:\Python27\python.exe
*/
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;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT size="4"&gt;Recommended reading:&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#333399"&gt;&lt;STRONG&gt;SAS or Python? Why not use both? Using Python functions inside SAS programs&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/sgf/2019/06/04/using-python-functions-inside-sas-programs/" target="_blank"&gt;https://blogs.sas.com/content/sgf/2019/06/04/using-python-functions-inside-sas-programs/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#333399"&gt;&lt;STRONG&gt;Using PROC FCMP Python Objects &lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://go.documentation.sas.com/?docsetId=lecompobjref&amp;amp;docsetTarget=p18qp136f91aaqn1h54v3b6pkant.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en"&gt;https://go.documentation.sas.com/?docsetId=lecompobjref&amp;amp;docsetTarget=p18qp136f91aaqn1h54v3b6pkant.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 18 Mar 2020 13:16:39 GMT</pubDate>
    <dc:creator>DanielRingqvist</dc:creator>
    <dc:date>2020-03-18T13:16:39Z</dc:date>
    <item>
      <title>Execute Python code from a Base SAS program using Proc FCMP</title>
      <link>https://communities.sas.com/t5/SAS-Community-Nordic/Execute-Python-code-from-a-Base-SAS-program-using-Proc-FCMP/m-p/632951#M272</link>
      <description>&lt;P&gt;Did you know Base SAS can execute Python code? Starting with May 2019 release of SAS 9.4M6, the PROC FCMP procedure added support for submitting and executing functions written in Python from within a SAS session using the new Python object. Proc FCMP is where you create your own SAS functions, and this alone is a brilliant way of cleaning up your code. Now with 9.4M6 you can also execute python functions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It could look like this simple example below, and there are many good sources to study such as blogs and SAS Documentation (links below snippet).&lt;/P&gt;
&lt;P&gt;The necessary steps are these two and are performed where your SAS Foundation is installed:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Install Python&lt;/LI&gt;
&lt;LI&gt;Add two environment variables in Windows (read doc to learn steps needed for other OS such as linux)&lt;/LI&gt;
&lt;LI&gt;Start SAS and submit this code&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Many more examples in SAS Documentation and blog entries.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*  ENVIRONMENT VARIABLES 
  - MAS_M2PATH: C:\SAS\SASHome\SASFoundation\9.4\tkmas\sasmisc\mas2py.py 
  - MAS_PYPATH: C:\Python27\python.exe
*/
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;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT size="4"&gt;Recommended reading:&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#333399"&gt;&lt;STRONG&gt;SAS or Python? Why not use both? Using Python functions inside SAS programs&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/sgf/2019/06/04/using-python-functions-inside-sas-programs/" target="_blank"&gt;https://blogs.sas.com/content/sgf/2019/06/04/using-python-functions-inside-sas-programs/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#333399"&gt;&lt;STRONG&gt;Using PROC FCMP Python Objects &lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://go.documentation.sas.com/?docsetId=lecompobjref&amp;amp;docsetTarget=p18qp136f91aaqn1h54v3b6pkant.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en"&gt;https://go.documentation.sas.com/?docsetId=lecompobjref&amp;amp;docsetTarget=p18qp136f91aaqn1h54v3b6pkant.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Mar 2020 13:16:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Community-Nordic/Execute-Python-code-from-a-Base-SAS-program-using-Proc-FCMP/m-p/632951#M272</guid>
      <dc:creator>DanielRingqvist</dc:creator>
      <dc:date>2020-03-18T13:16:39Z</dc:date>
    </item>
  </channel>
</rss>

