<?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 proc fcmp python code shows no output on submission in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-fcmp-python-code-shows-no-output-on-submission/m-p/773898#M245913</link>
    <description>&lt;P&gt;Hi everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to run python code in SAS Viya using proc fcmp. However the output is not getting displayed.&lt;/P&gt;
&lt;P&gt;I am using the code from the following link :&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A id="LPlnk513363" href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lecompobjref/p18qp136f91aaqn1h54v3b6pkant.htm" target="_blank" rel="noopener noreferrer" data-auth="NotApplicable" data-linkindex="0"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lecompobjref/p18qp136f91aaqn1h54v3b6pkant.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;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;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have attached screenshot of the result below for your reference.&lt;/P&gt;
&lt;P&gt;Thanks and regards,&lt;/P&gt;
&lt;P&gt;Mohammad Umair Kazi&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="python.PNG" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/64653i1C5371C58DD5DEB9/image-size/large?v=v2&amp;amp;px=999" role="button" title="python.PNG" alt="python.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 13 Oct 2021 11:43:02 GMT</pubDate>
    <dc:creator>kaziumair</dc:creator>
    <dc:date>2021-10-13T11:43:02Z</dc:date>
    <item>
      <title>proc fcmp python code shows no output on submission</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-fcmp-python-code-shows-no-output-on-submission/m-p/773898#M245913</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to run python code in SAS Viya using proc fcmp. However the output is not getting displayed.&lt;/P&gt;
&lt;P&gt;I am using the code from the following link :&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A id="LPlnk513363" href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lecompobjref/p18qp136f91aaqn1h54v3b6pkant.htm" target="_blank" rel="noopener noreferrer" data-auth="NotApplicable" data-linkindex="0"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lecompobjref/p18qp136f91aaqn1h54v3b6pkant.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;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;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have attached screenshot of the result below for your reference.&lt;/P&gt;
&lt;P&gt;Thanks and regards,&lt;/P&gt;
&lt;P&gt;Mohammad Umair Kazi&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="python.PNG" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/64653i1C5371C58DD5DEB9/image-size/large?v=v2&amp;amp;px=999" role="button" title="python.PNG" alt="python.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Oct 2021 11:43:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-fcmp-python-code-shows-no-output-on-submission/m-p/773898#M245913</guid>
      <dc:creator>kaziumair</dc:creator>
      <dc:date>2021-10-13T11:43:02Z</dc:date>
    </item>
    <item>
      <title>Re: proc fcmp python code shows no output on submission</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-fcmp-python-code-shows-no-output-on-submission/m-p/773931#M245922</link>
      <description>&lt;P&gt;Proc FCMP is "putting" texts/outputs into the Listing ODS, and SAS Studio seems not to have one. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try to add:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename t temp;
proc printto print=t;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;before the proc FCMP and then add:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc printto;
run;
data _null_;
  infile t;
  input;
  put _infile_;
run;
filename t;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;after the proc FCMP. And look into the log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Wed, 13 Oct 2021 14:20:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-fcmp-python-code-shows-no-output-on-submission/m-p/773931#M245922</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2021-10-13T14:20:31Z</dc:date>
    </item>
    <item>
      <title>Re: proc fcmp python code shows no output on submission</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-fcmp-python-code-shows-no-output-on-submission/m-p/775195#M246424</link>
      <description>&lt;P&gt;Bart is correct.&amp;nbsp;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:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;A global CMPLIB option to point to the storage location of the FCMP function I’m building.&lt;/LI&gt;
&lt;LI&gt;An OUTLIB option on the PROC FCMP statement.&lt;/LI&gt;
&lt;LI&gt;A FUNCTION statement to name the SAS function.&lt;/LI&gt;
&lt;LI&gt;A module name on the DECLARE statement to be sure any SAS function I build that references a Python function has a unique behind-the-scenes name.&lt;/LI&gt;
&lt;LI&gt;The FUNCTION statement's argument name (SASArg) on the CALL method.&lt;/LI&gt;
&lt;LI&gt;An FCMP-level RETURN statement to get the final value out of FCMP to the calling program.&lt;/LI&gt;
&lt;LI&gt;An ENDSUB statement.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;options set=MAS_PYPATH="point-to-your-python.exe"&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;set=MAS_M2PATH "point-to-your-mas2py.py"&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;STRONG&gt;&lt;FONT color="#993366"&gt;&amp;nbsp;cmplib=work.fcmp&lt;/FONT&gt;&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc fcmp &lt;STRONG&gt;&lt;FONT color="#993366"&gt;outlib=work.fcmp.pyfuncs&lt;/FONT&gt;&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#993366"&gt;function TimesFive(SASArg)&lt;/FONT&gt;&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;declare object py(python&lt;STRONG&gt;&lt;FONT color="#993366"&gt;('MySASFunc')&lt;/FONT&gt;&lt;/STRONG&gt;);&lt;/P&gt;
&lt;P&gt;submit into py;&lt;/P&gt;
&lt;P&gt;def MyFunc(arg1):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "Output: MyKey"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #This is a comment&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ReturnVar = arg1 * 5 #This is another comment&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return ReturnVar&lt;/P&gt;
&lt;P&gt;endsubmit;&lt;/P&gt;
&lt;P&gt;rc = py.publish();&lt;/P&gt;
&lt;P&gt;rc = py.call("MyFunc", &lt;STRONG&gt;&lt;FONT color="#993366"&gt;SASArg&lt;/FONT&gt;&lt;/STRONG&gt;);&lt;/P&gt;
&lt;P&gt;x = py.results["MyKey"];&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#993366"&gt;return(x);&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#993366"&gt;endsub;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data test;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; x=5;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; y=TimesFive(x);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Output:&lt;/P&gt;
&lt;P&gt;X&amp;nbsp; &amp;nbsp; &amp;nbsp;Y&lt;/P&gt;
&lt;P&gt;5&amp;nbsp; &amp;nbsp; &amp;nbsp;25&lt;/P&gt;</description>
      <pubDate>Tue, 19 Oct 2021 18:40:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-fcmp-python-code-shows-no-output-on-submission/m-p/775195#M246424</guid>
      <dc:creator>Mahult</dc:creator>
      <dc:date>2021-10-19T18:40:31Z</dc:date>
    </item>
  </channel>
</rss>

