<?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: most efficient method to loop a macro ? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/most-efficient-method-to-loop-a-macro/m-p/44622#M9149</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Dling. Will definitely try your code as well&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 08 Aug 2011 18:07:24 GMT</pubDate>
    <dc:creator>kansas</dc:creator>
    <dc:date>2011-08-08T18:07:24Z</dc:date>
    <item>
      <title>most efficient method to loop a macro ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/most-efficient-method-to-loop-a-macro/m-p/44612#M9139</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;After researching i found out two methods of looping a macro based on a dataset variable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;suppose my &lt;/P&gt;&lt;P&gt;dataset = data1 and variable=var1&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Purpose: I need to run "my_macro" for each &lt;STRONG&gt;var1 &lt;/STRONG&gt;value in the dataset&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;method1&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #339966;"&gt;%macro my_macro(var);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #339966;"&gt;&amp;lt;macro statements&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #339966;"&gt;%mend;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #339966;"&gt;data _null_;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #339966;"&gt;set data1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #339966;"&gt;call execute("%my_macro(" || var1 || ");");&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #339966;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;method2&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Can use macro arrays introduced in &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://www2.sas.com/proceedings/sugi31/040-31.pdf"&gt;http://www2.sas.com/proceedings/sugi31/040-31.pdf&lt;/A&gt;&lt;SPAN&gt; (Tight looping with macro arrays)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Both methods work perfectly.. But i want to know the most recommended method. (By number of lines, method1 seems the best for me. )&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 07 Aug 2011 04:02:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/most-efficient-method-to-loop-a-macro/m-p/44612#M9139</guid>
      <dc:creator>kansas</dc:creator>
      <dc:date>2011-08-07T04:02:53Z</dc:date>
    </item>
    <item>
      <title>most efficient method to loop a macro ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/most-efficient-method-to-loop-a-macro/m-p/44613#M9140</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Do you need to run the macro for each record or just for each unique value in var1?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 07 Aug 2011 04:06:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/most-efficient-method-to-loop-a-macro/m-p/44613#M9140</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-08-07T04:06:30Z</dc:date>
    </item>
    <item>
      <title>Re: most efficient method to loop a macro ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/most-efficient-method-to-loop-a-macro/m-p/44614#M9141</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;above is an example art297. My aim is to change the parameter value in a macro based on a dataset vallues.&lt;/P&gt;&lt;P&gt;yes for each record&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 07 Aug 2011 04:12:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/most-efficient-method-to-loop-a-macro/m-p/44614#M9141</guid>
      <dc:creator>kansas</dc:creator>
      <dc:date>2011-08-07T04:12:54Z</dc:date>
    </item>
    <item>
      <title>Re: most efficient method to loop a macro ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/most-efficient-method-to-loop-a-macro/m-p/44615#M9142</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Note from the SAS documentation, your CALL EXECUTE will not be executed until the DATA step has been completed (up to the RUN; statement).&amp;nbsp; And so the macro code cannot be a continuation of the current DATA step.&amp;nbsp; Given this situation, it will be important to know what SAS statements are contained in your SAS macro for execution.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also you will see the SAS execution logic with this additional diagnostic statement, at least prior to your DATA step:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;OPTIONS SOURCE SOURCE2 MACROGEN SYMBOLGEN /* MLOGIC */ MPRINT;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Scott Barry&lt;/P&gt;&lt;P&gt;SBBWorks, Inc. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Suggested Google advanced search argument, this topic / post:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;call execute site:sas.com&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 07 Aug 2011 14:23:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/most-efficient-method-to-loop-a-macro/m-p/44615#M9142</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2011-08-07T14:23:06Z</dc:date>
    </item>
    <item>
      <title>Re: most efficient method to loop a macro ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/most-efficient-method-to-loop-a-macro/m-p/44616#M9143</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;ok. this is what i'm trying to achieve&lt;BR /&gt;suppose a dataset containining var1&lt;BR /&gt;values &lt;BR /&gt;22&lt;/P&gt;&lt;P&gt;36&lt;/P&gt;&lt;P&gt;25&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i want to run my macro for each and every value of var1 (var1 values are unique).&lt;/P&gt;&lt;P&gt;so basically,this is what im going to achieve by using a call execute step.&lt;BR /&gt;&lt;SPAN style="color: #339966;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%my_macro(22);&lt;/P&gt;&lt;P&gt;%my_macro(36);&lt;/P&gt;&lt;P&gt;%my_macro(25);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and how does "SAS statements are contained in your SAS macro for execution" going to affect the program ?&lt;/P&gt;&lt;P&gt;my macro has some proc statements and some datasteps.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The code works as expected. I want know whether this code is against the coding best practices.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Aug 2011 04:17:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/most-efficient-method-to-loop-a-macro/m-p/44616#M9143</guid>
      <dc:creator>kansas</dc:creator>
      <dc:date>2011-08-08T04:17:20Z</dc:date>
    </item>
    <item>
      <title>Re: most efficient method to loop a macro ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/most-efficient-method-to-loop-a-macro/m-p/44617#M9144</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Can you post an actual example, including sample data along with your macro and code that calls it?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Aug 2011 12:31:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/most-efficient-method-to-loop-a-macro/m-p/44617#M9144</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-08-08T12:31:51Z</dc:date>
    </item>
    <item>
      <title>Re: most efficient method to loop a macro ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/most-efficient-method-to-loop-a-macro/m-p/44618#M9145</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; there are multiple solutions to have the same result.&lt;/P&gt;&lt;P&gt;I think your method is the best one even if the call execute will be executed at the end of your datastep. so first reading the whole dataset and then execute your macro calls.&lt;/P&gt;&lt;P&gt;the other method is like a nice "brainfuck" but can be really useful.&lt;/P&gt;&lt;P&gt;but if you want to use this option then you have to put all your variables in an array and then use the %do_over&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Aug 2011 12:48:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/most-efficient-method-to-loop-a-macro/m-p/44618#M9145</guid>
      <dc:creator>mojerry2</dc:creator>
      <dc:date>2011-08-08T12:48:47Z</dc:date>
    </item>
    <item>
      <title>Re: most efficient method to loop a macro ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/most-efficient-method-to-loop-a-macro/m-p/44619#M9146</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here's a method to loop a macro over every value in a dataset.&amp;nbsp; The macro itself sequentially reads a SAS dataset, so it doesn't use a macro array, and since it's done in a macro, there's no call execute.&amp;nbsp; All the methods above should work, this is another one of many approaches possible.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 9pt; background-color: white; font-family: Consolas;"&gt;%macro&lt;/STRONG&gt;&lt;SPAN style="background-color: white; font-family: Consolas; color: black; font-size: 9pt;"&gt; loop( data );&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="background-color: white; font-family: Consolas; color: blue; font-size: 9pt;"&gt;%let&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: Consolas; color: black; font-size: 9pt;"&gt; dsid=&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: Consolas; color: blue; font-size: 9pt;"&gt;%sysfunc&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: Consolas; color: black; font-size: 9pt;"&gt;(open(&amp;amp;data));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="background-color: white; font-family: Consolas; color: blue; font-size: 9pt;"&gt;%if&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: Consolas; color: black; font-size: 9pt;"&gt; (&amp;amp;dsid = &lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 9pt; background-color: white; font-family: Consolas;"&gt;0&lt;/STRONG&gt;&lt;SPAN style="background-color: white; font-family: Consolas; color: black; font-size: 9pt;"&gt;) &lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: Consolas; color: blue; font-size: 9pt;"&gt;%then&lt;/SPAN&gt; &lt;SPAN style="background-color: white; font-family: Consolas; color: blue; font-size: 9pt;"&gt;%do&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: Consolas; color: black; font-size: 9pt;"&gt;;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="background-color: white; font-family: Consolas; color: blue; font-size: 9pt;"&gt;%put&lt;/SPAN&gt; &lt;SPAN style="background-color: white; font-family: Consolas; color: blue; font-size: 9pt;"&gt;%sysfunc&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: Consolas; color: black; font-size: 9pt;"&gt;(sysmsg());&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="background-color: white; font-family: Consolas; color: blue; font-size: 9pt;"&gt;%return&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: Consolas; color: black; font-size: 9pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="background-color: white; font-family: Consolas; color: blue; font-size: 9pt;"&gt;%end&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: Consolas; color: black; font-size: 9pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: Consolas; color: black; font-size: 9pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="background-color: white; font-family: Consolas; color: blue; font-size: 9pt;"&gt;%syscall&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: Consolas; color: black; font-size: 9pt;"&gt; set(dsid);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * links sas dataset variables to macro variables, watch out for name collision ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: Consolas; color: black; font-size: 9pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="background-color: white; font-family: Consolas; color: blue; font-size: 9pt;"&gt;%do&lt;/SPAN&gt; &lt;SPAN style="background-color: white; font-family: Consolas; color: blue; font-size: 9pt;"&gt;%while&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: Consolas; color: black; font-size: 9pt;"&gt;( &lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: Consolas; color: blue; font-size: 9pt;"&gt;%sysfunc&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: Consolas; color: black; font-size: 9pt;"&gt;(fetch(&amp;amp;dsid)) = &lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 9pt; background-color: white; font-family: Consolas;"&gt;0&lt;/STRONG&gt;&lt;SPAN style="background-color: white; font-family: Consolas; color: black; font-size: 9pt;"&gt; );&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="background-color: white; font-family: Consolas; color: blue; font-size: 9pt;"&gt;%work(&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: Consolas; color: black; font-size: 9pt;"&gt;&lt;SPAN style="background-color: white; font-family: Consolas; color: black; font-size: 9pt;"&gt;&amp;amp;msgid)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * replace with anything you need like a macro call with arguments ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="background-color: white; font-family: Consolas; color: blue; font-size: 9pt;"&gt;%end&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: Consolas; color: black; font-size: 9pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: Consolas; color: black; font-size: 9pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="background-color: white; font-family: Consolas; color: blue; font-size: 9pt;"&gt;%let&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: Consolas; color: black; font-size: 9pt;"&gt; dsid=&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: Consolas; color: blue; font-size: 9pt;"&gt;%sysfunc&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: Consolas; color: black; font-size: 9pt;"&gt;(close(&amp;amp;dsid));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 9pt; background-color: white; font-family: Consolas;"&gt;%mend&lt;/STRONG&gt;&lt;SPAN style="background-color: white; font-family: Consolas; color: black; font-size: 9pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: Consolas; color: black; font-size: 9pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: Consolas; color: black; font-size: 9pt;"&gt;%macro work( arg );&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: Consolas; color: black; font-size: 9pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %put &amp;amp;arg;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: Consolas; color: black; font-size: 9pt;"&gt;%mend;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: Consolas; color: black; font-size: 9pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: Consolas; color: black; font-size: 9pt;"&gt;%&lt;STRONG&gt;&lt;EM&gt;loop&lt;/EM&gt;&lt;/STRONG&gt;( sashelp.adomsg )&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: Consolas; color: black; font-size: 9pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: Consolas; color: black; font-size: 9pt;"&gt;This version lists the "msgid" column from sashelp.adomsg dataset.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: Consolas; color: black; font-size: 9pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: Consolas; color: black; font-size: 9pt;"&gt;It illustrates the idea of using a macro to loop over SAS dataset and generate code.&amp;nbsp; And because it's all inside a macro, the looping and code generation is easier without needing to maintain arrays... etc.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: Consolas; color: black; font-size: 9pt;"&gt;Modify to suite your needs &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: Consolas; color: black; font-size: 9pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Aug 2011 14:08:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/most-efficient-method-to-loop-a-macro/m-p/44619#M9146</guid>
      <dc:creator>DLing</dc:creator>
      <dc:date>2011-08-08T14:08:44Z</dc:date>
    </item>
    <item>
      <title>Re: most efficient method to loop a macro ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/most-efficient-method-to-loop-a-macro/m-p/44620#M9147</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Most of the time when a macro is called with CALL EXECUTE and the macro generates SAS datastep and proc code you want to delay execution of the macro until after the data step is finished.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Therefore you would change your code to include %NRSTR.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; color: red; font-family: 'Courier New'; background-color: white;"&gt;call&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; color: black; font-family: 'Courier New'; background-color: white;"&gt; execute(&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; color: purple; font-family: 'Courier New'; background-color: white;"&gt;"%my_macro("&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; color: black; font-family: 'Courier New'; background-color: white;"&gt; || var1 || &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; color: purple; font-family: 'Courier New'; background-color: white;"&gt;");"&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; color: black; font-family: 'Courier New'; background-color: white;"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; color: black; font-family: 'Courier New'; background-color: white;"&gt;to &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; color: red; font-family: 'Courier New'; background-color: white;"&gt;call&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; color: black; font-family: 'Courier New'; background-color: white;"&gt; execute(&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; color: purple; font-family: 'Courier New'; background-color: white;"&gt;"%nrstr(%my_macro("&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; color: black; font-family: 'Courier New'; background-color: white;"&gt; || var1 || &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; color: purple; font-family: 'Courier New'; background-color: white;"&gt;");)"&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; color: black; font-family: 'Courier New'; background-color: white;"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; color: black; font-family: 'Courier New'; background-color: white;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; color: black; background-color: white;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Using NRSTR will prevent the macro from being called when CALL EXECUTE "executes".&amp;nbsp; This is usually the action you need, especially if the macro being called uses data or proc steps to create or alter macro variables that are then used in subsequent program steps.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think it is all explained in detail in the documentation which I encourage you to read.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Aug 2011 14:20:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/most-efficient-method-to-loop-a-macro/m-p/44620#M9147</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2011-08-08T14:20:03Z</dc:date>
    </item>
    <item>
      <title>Re: most efficient method to loop a macro ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/most-efficient-method-to-loop-a-macro/m-p/44621#M9148</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;STRONG&gt;"so first reading the whole dataset and then execute your macro calls." &lt;BR /&gt;&lt;/STRONG&gt;so macro statement wont be executed until the datastep completely finishes ? All this time i was thinking that macro statement gets executed at the end of each iteration .&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Aug 2011 16:52:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/most-efficient-method-to-loop-a-macro/m-p/44621#M9148</guid>
      <dc:creator>kansas</dc:creator>
      <dc:date>2011-08-08T16:52:48Z</dc:date>
    </item>
    <item>
      <title>Re: most efficient method to loop a macro ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/most-efficient-method-to-loop-a-macro/m-p/44622#M9149</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Dling. Will definitely try your code as well&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Aug 2011 18:07:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/most-efficient-method-to-loop-a-macro/m-p/44622#M9149</guid>
      <dc:creator>kansas</dc:creator>
      <dc:date>2011-08-08T18:07:24Z</dc:date>
    </item>
    <item>
      <title>most efficient method to loop a macro ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/most-efficient-method-to-loop-a-macro/m-p/44623#M9150</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;As a list of calling parameters is not always sourced from a data set, you might like a look at this alternative.&lt;/P&gt;&lt;P&gt;Not limited to execution within a data step, there is a macro looper described in a SUGI paper &lt;A href="http://www2.sas.com/proceedings/sugi31/012-31.pdf"&gt;http://www2.sas.com/proceedings/sugi31/012-31.pdf&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;peterC&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Aug 2011 13:25:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/most-efficient-method-to-loop-a-macro/m-p/44623#M9150</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2011-08-09T13:25:56Z</dc:date>
    </item>
  </channel>
</rss>

