<?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: Running a macro multiple times (looped) but based on a list of values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Running-a-macro-multiple-times-looped-but-based-on-a-list-of/m-p/555177#M154490</link>
    <description>&lt;P&gt;I will try this! Thanks&lt;/P&gt;</description>
    <pubDate>Tue, 30 Apr 2019 18:58:58 GMT</pubDate>
    <dc:creator>td1345</dc:creator>
    <dc:date>2019-04-30T18:58:58Z</dc:date>
    <item>
      <title>Running a macro multiple times (looped) but based on a list of values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-a-macro-multiple-times-looped-but-based-on-a-list-of/m-p/555050#M154451</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to run my macro (%tti(number)) that performs a large series of operations using an input value of 'number'. I have 2000 such numbers that changes the output of the macro. I have looped though them all using a simple loop macro:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%macro loop(start,stop);
%do iii=&amp;amp;start %to &amp;amp;stop;
%tti(&amp;amp;iii);
%end;
%mend();&lt;/PRE&gt;&lt;P&gt;However, now I would like to create the same macro but no do start to stop but rather run the macro based on input numbers, lets says 3,5,7,33,99.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried to use code presented on this forum with no success.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%do_this(3 5 7 33 99);


%macro do_this(ids);
    %let num_ids=%sysfunc(countw(&amp;amp;ids));
    %do i=1 %to &amp;amp;num_ids;
         %let this_id=%scan(&amp;amp;ids,&amp;amp;i,%str( ));
         %tti(&amp;amp;this_id);
         run;
    %end;
%mend;&lt;/PRE&gt;&lt;P&gt;This macro runs the %tti() but using wrong input and sometimes gets stuck on the last input variable (in this case 99) and reruns it indefinitely. When inputting only 2 numbers in the list it only performs the 1st.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Apr 2019 14:09:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-a-macro-multiple-times-looped-but-based-on-a-list-of/m-p/555050#M154451</guid>
      <dc:creator>td1345</dc:creator>
      <dc:date>2019-04-30T14:09:09Z</dc:date>
    </item>
    <item>
      <title>Re: Running a macro multiple times (looped) but based on a list of values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-a-macro-multiple-times-looped-but-based-on-a-list-of/m-p/555051#M154452</link>
      <description>&lt;P&gt;Nothing serious is wrong with your posted code.&lt;/P&gt;
&lt;P&gt;Make sure that the TTI macro is not changing the macro variables I or NUM_IDS.&lt;/P&gt;
&lt;P&gt;Remember to ALWAYS declare the macro variables that are local to your macro as %LOCAL to avoid this type of issue when nesting macro calls.&amp;nbsp; So your TTI macro might have a %DO loop that also using I as the index macro variable name. Like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro tti(arg1);
%local i;
....
%do i=
 ...

%mend tti;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And if it does NOT have the %LOCAL statement then the macro variable I that the %DO loop would modify would be the one defined in DO_THIS instead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So your little DO_THIS macro should do the same thing just in case you decide to call it from some other macro.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro do_this(ids);
%local num_ids i this_id;
    %let num_ids=%sysfunc(countw(&amp;amp;ids));
    %do i=1 %to &amp;amp;num_ids;
         %let this_id=%scan(&amp;amp;ids,&amp;amp;i,%str( ));
         %tti(&amp;amp;this_id);
    %end;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Apr 2019 14:18:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-a-macro-multiple-times-looped-but-based-on-a-list-of/m-p/555051#M154452</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-04-30T14:18:34Z</dc:date>
    </item>
    <item>
      <title>Re: Running a macro multiple times (looped) but based on a list of values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-a-macro-multiple-times-looped-but-based-on-a-list-of/m-p/555055#M154453</link>
      <description>&lt;P&gt;Run your macro off a dataset with call execute():&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data control;
input i;
datalines;
3
5
7
33
99
;
run;

data _null_;
set control;
call execute(cats('%nrstr(%tti(',i,'))'));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 30 Apr 2019 14:18:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-a-macro-multiple-times-looped-but-based-on-a-list-of/m-p/555055#M154453</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-04-30T14:18:51Z</dc:date>
    </item>
    <item>
      <title>Re: Running a macro multiple times (looped) but based on a list of values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-a-macro-multiple-times-looped-but-based-on-a-list-of/m-p/555056#M154454</link>
      <description>&lt;P&gt;The data step DO loop allows you to use a list of values like that. Why not just use a data step to generate the macro calls?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  do id=3,5,7,33,99;
    call execute(cats('%nrstr(%tti)(',id,')'));
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 30 Apr 2019 14:21:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-a-macro-multiple-times-looped-but-based-on-a-list-of/m-p/555056#M154454</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-04-30T14:21:51Z</dc:date>
    </item>
    <item>
      <title>Re: Running a macro multiple times (looped) but based on a list of values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-a-macro-multiple-times-looped-but-based-on-a-list-of/m-p/555176#M154489</link>
      <description>&lt;P&gt;Thanks alot!&lt;/P&gt;</description>
      <pubDate>Tue, 30 Apr 2019 18:58:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-a-macro-multiple-times-looped-but-based-on-a-list-of/m-p/555176#M154489</guid>
      <dc:creator>td1345</dc:creator>
      <dc:date>2019-04-30T18:58:27Z</dc:date>
    </item>
    <item>
      <title>Re: Running a macro multiple times (looped) but based on a list of values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-a-macro-multiple-times-looped-but-based-on-a-list-of/m-p/555177#M154490</link>
      <description>&lt;P&gt;I will try this! Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 30 Apr 2019 18:58:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-a-macro-multiple-times-looped-but-based-on-a-list-of/m-p/555177#M154490</guid>
      <dc:creator>td1345</dc:creator>
      <dc:date>2019-04-30T18:58:58Z</dc:date>
    </item>
  </channel>
</rss>

