<?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 How to use call execute when parameters are global variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-call-execute-when-parameters-are-global-variables/m-p/478030#M286288</link>
    <description>&lt;P&gt;All,&amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;Wondering what is the correct way to call a SAS Macro using the call execute method when it has global variables as parameters.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; The following is throwing some errors as shown below:&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data _null_; 
	If &amp;amp;Flag^= 1 Then 
  		call execute('%nrstr(%MyMacro('||&amp;amp;Param1||','||&amp;amp;Param2||','||&amp;amp;Param3||','||&amp;amp;Param4||'))');
	Else 
		put "**l Data Is Turned On" ;
Run; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Errors:&amp;nbsp;&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="image.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/21777i3380F3AC925DB7DA/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 13 Jul 2018 20:21:54 GMT</pubDate>
    <dc:creator>UdayGuntupalli</dc:creator>
    <dc:date>2018-07-13T20:21:54Z</dc:date>
    <item>
      <title>How to use call execute when parameters are global variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-call-execute-when-parameters-are-global-variables/m-p/478030#M286288</link>
      <description>&lt;P&gt;All,&amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;Wondering what is the correct way to call a SAS Macro using the call execute method when it has global variables as parameters.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; The following is throwing some errors as shown below:&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data _null_; 
	If &amp;amp;Flag^= 1 Then 
  		call execute('%nrstr(%MyMacro('||&amp;amp;Param1||','||&amp;amp;Param2||','||&amp;amp;Param3||','||&amp;amp;Param4||'))');
	Else 
		put "**l Data Is Turned On" ;
Run; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Errors:&amp;nbsp;&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="image.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/21777i3380F3AC925DB7DA/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jul 2018 20:21:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-call-execute-when-parameters-are-global-variables/m-p/478030#M286288</guid>
      <dc:creator>UdayGuntupalli</dc:creator>
      <dc:date>2018-07-13T20:21:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to use call execute when parameters are global variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-call-execute-when-parameters-are-global-variables/m-p/478032#M286289</link>
      <description>&lt;P&gt;See if this gives some ideas:&lt;/P&gt;
&lt;PRE&gt;%let param1= Sometext;

%macro dummy(parm);
%put Passed Parm value in macro Dummy was &amp;amp;parm.;
%mend;

data _null_;
  call execute('%dummy(&amp;amp;param1.)');
run;&lt;/PRE&gt;
&lt;P&gt;With the global macro variable inside the single quote it does not attempt to resolve until the call execute stack starts executing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This specific code generates a note that Call Execute routine execute successfully but no SAS statements were generated because this is a very trivial macro with only %put, which does not generate any statements. About as bare bones as was possible demonstrate one potential route to a solution.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jul 2018 20:32:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-call-execute-when-parameters-are-global-variables/m-p/478032#M286289</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-07-13T20:32:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to use call execute when parameters are global variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-call-execute-when-parameters-are-global-variables/m-p/478035#M286290</link>
      <description>&lt;P&gt;The error message is showing your mistake and it is really unrelated to CALL EXECUTE.&amp;nbsp; Just to how macro variable references themselves work.&lt;/P&gt;
&lt;P&gt;If you set a macro variable to string of characters longer than 32 characters.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let x=this_is_too_long_to_be_a_valid_sas_variable_name;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And then try to expand that macro variable in the middle of a SAS statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  x=&amp;amp;x ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you have tried to run this SAS code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  x=this_is_too_long_to_be_a_valid_sas_variable_name;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which is clearly invalid.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the value you want to pass is based on macro variables instead of data set variables then make sure to enclose them in quotes.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_; 
  if &amp;amp;Flag^= 1 then
    call execute('%nrstr(%mymacro)('||"&amp;amp;param1,&amp;amp;param2,&amp;amp;param3,&amp;amp;param4"||')' )
  ;
  else put "**l Data Is Turned On" ;
run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you use double quotes then the values of the macro variables will be expanded when the data step is compiled. If you use single quotes then they will be expanded when the code is pushed onto the stack by call execute.&amp;nbsp; If you use single quotes and also wait to close the %NRSTR() macro function call until after the macro parameters then the macro variables will be expanded when the call is pull off of the stack to run after the data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Of course if you are running the latest version of SAS (9.4M5) then you can eliminate the data step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if (&amp;amp;flag = 1) %then %do;
  %put "**l Data Is Turned On" ;
%end;
%else %do;
  %mymacro(&amp;amp;param1,&amp;amp;param2,&amp;amp;param3,&amp;amp;param4)
%end; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 13 Jul 2018 21:07:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-call-execute-when-parameters-are-global-variables/m-p/478035#M286290</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-07-13T21:07:55Z</dc:date>
    </item>
  </channel>
</rss>

