<?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 SAS macro in conjunction with PROC PYTHON in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-in-conjunction-with-PROC-PYTHON/m-p/982195#M379268</link>
    <description>&lt;P&gt;Hello Everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to add a dynamic feature to the topic of&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Passing-Parameters-from-SAS-to-Python-Script/td-p/874601" target="_self"&gt;Passing-Parameters-from-SAS-to-Python-Script&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Therefore, I wanted to use a SAS macro as a wrapper around the python code, that&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/335473"&gt;@HarrySnart&lt;/a&gt;&amp;nbsp;used.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro print_macval_not_working(p_macvarname=);
    %let myvar="&amp;amp;p_macvarname.";
    %PUT &amp;amp;=myvar;
proc python;
submit;
x = SAS.symget('myvar')
print('macro variable myvar = ' + x)

py_var = 'Inside python'
SAS.symput('macrovar', py_var)
endsubmit;
    run;
    %put &amp;amp;=macrovar;
    %put &amp;amp;=myvar;
%mend;
%print_macval_not_working(p_macvarname=test);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;However, I get this ERROR message, which I would like to understand:&lt;/P&gt;
&lt;PRE&gt;&lt;FONT color="#993300"&gt;&lt;CODE class=" language-sas"&gt;&lt;FONT color="#FF0000"&gt;ERROR: Submit block cannot be directly placed in a macro. Instead, place the submit block into a file first and then use %include 
       to include the file within a macro definition.
ERROR:  Submit code parse failure.
ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/FONT&gt;&lt;/CODE&gt;&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;Why is it just with the PROC PYTHON Procedure not possible to use a macro?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I just create a simple macro without the python procedure, it works fine:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro print_macval_works(p_macvarname=);
    %let myvar="&amp;amp;p_macvarname.";
    %PUT &amp;amp;=myvar;
%mend;
%print_macval_works(p_macvarname=ibson);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What are the "special circumstances" that prevent the macro "&lt;CODE class=" language-sas"&gt;print_macval_not_working&lt;/CODE&gt;" from working?&lt;/P&gt;</description>
    <pubDate>Tue, 20 Jan 2026 12:09:22 GMT</pubDate>
    <dc:creator>FK21</dc:creator>
    <dc:date>2026-01-20T12:09:22Z</dc:date>
    <item>
      <title>SAS macro in conjunction with PROC PYTHON</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-in-conjunction-with-PROC-PYTHON/m-p/982195#M379268</link>
      <description>&lt;P&gt;Hello Everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to add a dynamic feature to the topic of&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Passing-Parameters-from-SAS-to-Python-Script/td-p/874601" target="_self"&gt;Passing-Parameters-from-SAS-to-Python-Script&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Therefore, I wanted to use a SAS macro as a wrapper around the python code, that&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/335473"&gt;@HarrySnart&lt;/a&gt;&amp;nbsp;used.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro print_macval_not_working(p_macvarname=);
    %let myvar="&amp;amp;p_macvarname.";
    %PUT &amp;amp;=myvar;
proc python;
submit;
x = SAS.symget('myvar')
print('macro variable myvar = ' + x)

py_var = 'Inside python'
SAS.symput('macrovar', py_var)
endsubmit;
    run;
    %put &amp;amp;=macrovar;
    %put &amp;amp;=myvar;
%mend;
%print_macval_not_working(p_macvarname=test);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;However, I get this ERROR message, which I would like to understand:&lt;/P&gt;
&lt;PRE&gt;&lt;FONT color="#993300"&gt;&lt;CODE class=" language-sas"&gt;&lt;FONT color="#FF0000"&gt;ERROR: Submit block cannot be directly placed in a macro. Instead, place the submit block into a file first and then use %include 
       to include the file within a macro definition.
ERROR:  Submit code parse failure.
ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/FONT&gt;&lt;/CODE&gt;&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;Why is it just with the PROC PYTHON Procedure not possible to use a macro?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I just create a simple macro without the python procedure, it works fine:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro print_macval_works(p_macvarname=);
    %let myvar="&amp;amp;p_macvarname.";
    %PUT &amp;amp;=myvar;
%mend;
%print_macval_works(p_macvarname=ibson);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What are the "special circumstances" that prevent the macro "&lt;CODE class=" language-sas"&gt;print_macval_not_working&lt;/CODE&gt;" from working?&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jan 2026 12:09:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-in-conjunction-with-PROC-PYTHON/m-p/982195#M379268</guid>
      <dc:creator>FK21</dc:creator>
      <dc:date>2026-01-20T12:09:22Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro in conjunction with PROC PYTHON</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-in-conjunction-with-PROC-PYTHON/m-p/982207#M379278</link>
      <description>&lt;P&gt;Python code depends on the layout to separate statements and identify blocks (through indentation).&lt;/P&gt;
&lt;P&gt;Since a macro is tokenized upon compilation, this layout is lost and the Python code would become unusable. The %INCLUDE, OTOH, is executed when the macro executes, and will therefore result in the code being inserted as it is in the file, with the layout intact&lt;/P&gt;
&lt;P&gt;This is the same reason that also prohibits use of DATALINES in a macro.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jan 2026 13:24:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-in-conjunction-with-PROC-PYTHON/m-p/982207#M379278</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2026-01-20T13:24:19Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro in conjunction with PROC PYTHON</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-in-conjunction-with-PROC-PYTHON/m-p/982210#M379279</link>
      <description>&lt;P&gt;I'm just guessing, but PYTHON cares about leading white space (indenting) in code.&amp;nbsp; When you compile a macro, it does not preserve white space in the code it will generate when executed.&amp;nbsp; So likely a compiled macro can't generate valid python code, if the python code is inline in the macro definition.&amp;nbsp; It's the same reason you can't use a CARDS statement inside a macro.&amp;nbsp; The %include approach kindly recommended in the error message sounds like a good workaround.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jan 2026 13:32:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-in-conjunction-with-PROC-PYTHON/m-p/982210#M379279</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2026-01-20T13:32:21Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro in conjunction with PROC PYTHON</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-in-conjunction-with-PROC-PYTHON/m-p/982219#M379280</link>
      <description>Thank you, Kurt!</description>
      <pubDate>Tue, 20 Jan 2026 15:04:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-in-conjunction-with-PROC-PYTHON/m-p/982219#M379280</guid>
      <dc:creator>FK21</dc:creator>
      <dc:date>2026-01-20T15:04:55Z</dc:date>
    </item>
  </channel>
</rss>

