<?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 Re: call a macro inside call execute, and macro variables resolution in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/call-a-macro-inside-call-execute-and-macro-variables-resolution/m-p/195173#M36713</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;Thank you very very much, I understand, I'll change the code as you suggest.&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;So two last questions:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;why that code made macrovar global? just curious&lt;/LI&gt;&lt;LI&gt;is there a function to resolve a macrovariable at execution-time without using neither a datastep nor a proc?&lt;/LI&gt;&lt;/UL&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 03 Jul 2015 10:53:55 GMT</pubDate>
    <dc:creator>Edoedoedo</dc:creator>
    <dc:date>2015-07-03T10:53:55Z</dc:date>
    <item>
      <title>call a macro inside call execute, and macro variables resolution</title>
      <link>https://communities.sas.com/t5/SAS-Programming/call-a-macro-inside-call-execute-and-macro-variables-resolution/m-p/195170#M36710</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;please check out this code snippet which is driving me crazy:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __jive_macro_name="quote" class="jive_text_macro jive_macro_quote"&gt;
&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;data dataset;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; par = 1;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; var = 'Valore';&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%macro mmm(par1); &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; %put macrovar1=&amp;amp;macrovar;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; proc sql;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; select var || put(time(),time10.) into :macrovar from dataset where par = &amp;amp;par1;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; quit;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; %put macrovar2=&amp;amp;macrovar;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%mend;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;data _NULL_;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; call execute("%mmm(1)");&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I expect that macrovar1 puts "not resolved" and macrovar2 puts e.g. "Valore 15:00:00". Instead, I get "not resolved" either in macrovar1 and in macrovar2. Moreover, "macrovar" becomes oddly a global macro variable, hence if I execute again this snippet I get "Valore 15:00:00" either in macrovar1 and in macrovar2, which does not make any sense since I expect macrovar1 to be "not resolved" and macrovar2 to be "Valore 15:01:00" i.e. a new value instead of keeping the old value.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, if I replace the last data step simply with %mmm(1); it works exactly as expected. So what is "call execute" doing wrong?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope I made myself clear.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks a lot&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 03 Jul 2015 10:09:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/call-a-macro-inside-call-execute-and-macro-variables-resolution/m-p/195170#M36710</guid>
      <dc:creator>Edoedoedo</dc:creator>
      <dc:date>2015-07-03T10:09:31Z</dc:date>
    </item>
    <item>
      <title>Re: call a macro inside call execute, and macro variables resolution</title>
      <link>https://communities.sas.com/t5/SAS-Programming/call-a-macro-inside-call-execute-and-macro-variables-resolution/m-p/195171#M36711</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The macro is executed when it is called during the &lt;SPAN style="text-decoration: underline;"&gt;compilation&lt;/SPAN&gt; phase of the data _NULL_ step, but the proc sql runs after the &lt;SPAN style="text-decoration: underline;"&gt;text&lt;/SPAN&gt; created by the macro is handed over to the SAS system when the data _NULL_ step has finished its &lt;SPAN style="text-decoration: underline;"&gt;execution&lt;/SPAN&gt; phase. Therefore the macro reaches its %mend long before the sql ever runs.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can watch this when you put&lt;/P&gt;&lt;P&gt;options mlogic mprint;&lt;/P&gt;&lt;P&gt;right before the data _null_ step.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 03 Jul 2015 10:26:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/call-a-macro-inside-call-execute-and-macro-variables-resolution/m-p/195171#M36711</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2015-07-03T10:26:49Z</dc:date>
    </item>
    <item>
      <title>Re: call a macro inside call execute, and macro variables resolution</title>
      <link>https://communities.sas.com/t5/SAS-Programming/call-a-macro-inside-call-execute-and-macro-variables-resolution/m-p/195172#M36712</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;To be honest, I don't see why you would want to be selecting data into a macro variable in code which is called by call execute.&amp;nbsp; The basic premise of using call execute is to generate code based on the output from a datastep.&amp;nbsp; So if i take a problem, say I want to print all 4 ABC variables, then I wouldn't call execute a macro which creates a list of of these variables, as I already have the datastep for such a thing:&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do i="ABC1","ABC2","ABC3","ABC4";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; call execute('%print_macro (var='||strip(i)||');');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;as KurtBremser has stated, you are trying to generate code (via the pre-processor) at two separate stages which doesn't make sense.&amp;nbsp; Get the information you would put in macro variables into a dataset - remembering that you can do pretty much anything here, distinct lists for loops, do, calculations etc. then use that input dataset as the driver for call execute to generate the code from. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 03 Jul 2015 10:45:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/call-a-macro-inside-call-execute-and-macro-variables-resolution/m-p/195172#M36712</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-07-03T10:45:07Z</dc:date>
    </item>
    <item>
      <title>Re: call a macro inside call execute, and macro variables resolution</title>
      <link>https://communities.sas.com/t5/SAS-Programming/call-a-macro-inside-call-execute-and-macro-variables-resolution/m-p/195173#M36713</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;Thank you very very much, I understand, I'll change the code as you suggest.&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;So two last questions:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;why that code made macrovar global? just curious&lt;/LI&gt;&lt;LI&gt;is there a function to resolve a macrovariable at execution-time without using neither a datastep nor a proc?&lt;/LI&gt;&lt;/UL&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 03 Jul 2015 10:53:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/call-a-macro-inside-call-execute-and-macro-variables-resolution/m-p/195173#M36713</guid>
      <dc:creator>Edoedoedo</dc:creator>
      <dc:date>2015-07-03T10:53:55Z</dc:date>
    </item>
    <item>
      <title>Re: call a macro inside call execute, and macro variables resolution</title>
      <link>https://communities.sas.com/t5/SAS-Programming/call-a-macro-inside-call-execute-and-macro-variables-resolution/m-p/195174#M36714</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Since the SQL runs after the data _null_ step and therefore outside of the macro, it puts macrovar in the global table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I don't quite understand your second question. Macro variables are resolved when referenced with &amp;amp;macrovar.&lt;/P&gt;&lt;P&gt;Could you be more specific?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 03 Jul 2015 11:09:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/call-a-macro-inside-call-execute-and-macro-variables-resolution/m-p/195174#M36714</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2015-07-03T11:09:17Z</dc:date>
    </item>
    <item>
      <title>Re: call a macro inside call execute, and macro variables resolution</title>
      <link>https://communities.sas.com/t5/SAS-Programming/call-a-macro-inside-call-execute-and-macro-variables-resolution/m-p/195175#M36715</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks, I mean that for instance the macro would be:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: 'courier new', courier;"&gt;%macro mmm(par1);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&amp;nbsp; &lt;SPAN style="line-height: 1.5em;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: 'courier new', courier;"&gt;&amp;nbsp; proc sql;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: 'courier new', courier;"&gt;&amp;nbsp; select var || put(time(),time10.) into :macrovar from dataset where par = &amp;amp;par1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: 'courier new', courier;"&gt;&amp;nbsp; quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; options something=&amp;amp;macrovar;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: 'courier new', courier;"&gt;%mend;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: 'courier new', courier;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;SPAN style="font-style: inherit; font-family: arial, helvetica, sans-serif; font-weight: inherit;"&gt;meaning that for instance I need to use the macrovar variable (calculated within the macro) later in the same macro neither in a datastep nor in a proc step (in the example I'm using "options" which does not have any sense, it is just to explain what I mean). As you taught me, this code would not work because &amp;amp;macrovar is resolved at compile time (hence undefined).&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;SPAN style="font-style: inherit; font-family: arial, helvetica, sans-serif; font-weight: inherit;"&gt;How would you rewrite that line in order to use that macrovariable calculated just before? I'm looking for something like "options something=symget('macrovar');" (which is awful, I know).&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: 'courier new', courier;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: 'courier new', courier;"&gt;Thanks again&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 03 Jul 2015 15:17:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/call-a-macro-inside-call-execute-and-macro-variables-resolution/m-p/195175#M36715</guid>
      <dc:creator>Edoedoedo</dc:creator>
      <dc:date>2015-07-03T15:17:20Z</dc:date>
    </item>
    <item>
      <title>Re: call a macro inside call execute, and macro variables resolution</title>
      <link>https://communities.sas.com/t5/SAS-Programming/call-a-macro-inside-call-execute-and-macro-variables-resolution/m-p/195176#M36716</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;your question does not make sense&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;gt; is there a function to resolve a macrovariable at execution-time without using neither a datastep nor a proc?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;we have macro variables (%let)&lt;/P&gt;&lt;P&gt;and macro definitions (%macro x ... %mend x;)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;resolution means&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. substitution:&lt;/P&gt;&lt;P&gt;1.1 assignment %let a = apples;&lt;/P&gt;&lt;P&gt;1.2 substitution: %put I like &amp;amp;a;&lt;/P&gt;&lt;P&gt;also: %put info: &amp;amp;=a;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. expansion: &lt;/P&gt;&lt;P&gt;2.1 definition: %macro do_loop(dim=3)%do i = 1 %to &amp;amp;dim; %put echo &amp;amp;=i;%end;%mend;&lt;/P&gt;&lt;P&gt;2.2 expand: %do_loop(dim=4)&lt;/P&gt;&lt;P&gt;%put i=1;&lt;/P&gt;&lt;P&gt;%put i=2;&lt;/P&gt;&lt;P&gt;%put i=3;&lt;/P&gt;&lt;P&gt;%put i=4;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;summary:&lt;/P&gt;&lt;P&gt;macro variable values are referenced, substituted, with an ampersand before the macro variable name&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;macro definitions are expanded, with a percent sign before the macro definition name&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;please reframe your question&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 03 Jul 2015 16:08:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/call-a-macro-inside-call-execute-and-macro-variables-resolution/m-p/195176#M36716</guid>
      <dc:creator>Ron_MacroMaven</dc:creator>
      <dc:date>2015-07-03T16:08:59Z</dc:date>
    </item>
    <item>
      <title>Re: call a macro inside call execute, and macro variables resolution</title>
      <link>https://communities.sas.com/t5/SAS-Programming/call-a-macro-inside-call-execute-and-macro-variables-resolution/m-p/195177#M36717</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You wouldn't do it that way.&amp;nbsp; So say I want to do that bit of code:&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: 'courier new', courier;"&gt;%let par1=something;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: 'courier new', courier;"&gt;data _null_;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set dataset (where=(par=&amp;amp;par1.));&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; call execute(cats('options something=',put(time(),time10.),';'));&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: 'courier new', courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: 'courier new', courier;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: 'courier new', courier;"&gt;Note that the above will generate the options statement once for each record returned from dataset where the where condition is true.&amp;nbsp; &lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 03 Jul 2015 17:51:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/call-a-macro-inside-call-execute-and-macro-variables-resolution/m-p/195177#M36717</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-07-03T17:51:33Z</dc:date>
    </item>
    <item>
      <title>Re: call a macro inside call execute, and macro variables resolution</title>
      <link>https://communities.sas.com/t5/SAS-Programming/call-a-macro-inside-call-execute-and-macro-variables-resolution/m-p/195178#M36718</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you want a "persistent" macro variable that keeps its value from macro call to macro call, you need to put it into the global macrovariable table by using the %global macrovar; statement.&lt;/P&gt;&lt;P&gt;Your initial problem was that, by using call execute within a data step, you created confusion about when what piece of code was executed. I advise to follow the KISS principle and not call a macro with call execute, but a "macro-less" version of the code with call execute, unless you completely know what you're doing (which will take some time regarding the use of the macro language).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was alos initially baffled by your problem.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Jul 2015 09:23:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/call-a-macro-inside-call-execute-and-macro-variables-resolution/m-p/195178#M36718</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2015-07-06T09:23:00Z</dc:date>
    </item>
    <item>
      <title>Re: call a macro inside call execute, and macro variables resolution</title>
      <link>https://communities.sas.com/t5/SAS-Programming/call-a-macro-inside-call-execute-and-macro-variables-resolution/m-p/195179#M36719</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Consider the timing of when the macro runs.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In your original line:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; line-height: 1.5em; font-family: 'courier new', courier;"&gt;&amp;nbsp; call execute("%mmm(1)");&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;You are expanding the macro BEFORE the data step executes and storing the code generated by that macro into the literal string that you pass to call execute.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;So the %PUT statements run BEFORE the data step starts and what is passed to CALL EXECUTE are the lines of code that the macro generated.&amp;nbsp; It is as if you coded&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 12pt; font-family: 'courier new', courier;"&gt;&amp;nbsp; call execute('proc sql; select ....');&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: 'courier new', courier;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;If you change to using single quotes: &lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 12pt; font-family: 'courier new', courier;"&gt;&amp;nbsp; call execute('%mmm(1)');&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;then the macro is expanded when it is pushed on the CALL EXECUTE stack.&amp;nbsp; So the %PUTs run while the code is being put onto the stack and the same SQL code is put on the stack to run after the data step finishes.&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;If you change to using %NRSTR() inside of single quotes: &lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 12pt; font-family: 'courier new', courier;"&gt;&amp;nbsp; call execute('%nrstr(%%mmm)(1)');&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 10pt;"&gt;then the macro call is pushed onto the CALL EXECUTE stack.&amp;nbsp; So now the %PUTs run after the data step has finished.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Jul 2015 14:12:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/call-a-macro-inside-call-execute-and-macro-variables-resolution/m-p/195179#M36719</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2015-07-06T14:12:08Z</dc:date>
    </item>
  </channel>
</rss>

