<?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: Loop a macro through 2 different sets of indices, one of which is staggered in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Loop-a-macro-through-2-different-sets-of-indices-one-of-which-is/m-p/455489#M115216</link>
    <description>&lt;P&gt;You can do what you want like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro runit;
  %local sexes index i j sex;
  %let sexes=MF;
  %do index=1 %to 3;
    %do i=1 %to 2;
      %let sex=%substr(&amp;amp;sexes,&amp;amp;i,1);
      %filter_data(&amp;amp;sex,&amp;amp;index,%eval(&amp;amp;index+10),%eval(&amp;amp;index+11),%eval(&amp;amp;index+12));
      %end;
    %end;
%mend;
%runit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But you will get more mileage with large data if you use the conditions to split the data in one datastep, e.g.:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro split_data(sexes,indexes);
  %local i j;
  data
  %do i=1 %to %sysfunc(countw(&amp;amp;sexes));
    %do j=1 %to %sysfunc(countw(&amp;amp;indexes));
      %let sex=%scan(&amp;amp;sexes,&amp;amp;i);
      %let index=%scan(&amp;amp;indexes,&amp;amp;j);
      class_&amp;amp;sex._&amp;amp;index
      %end;
    %end;
    ;
  set sashelp.class;
  %do i=1 %to %sysfunc(countw(&amp;amp;sexes));
    %do j=1 %to %sysfunc(countw(&amp;amp;indexes));
      %let sex=%scan(&amp;amp;sexes,&amp;amp;i);
      %let index=%scan(&amp;amp;indexes,&amp;amp;j);
      if sex="&amp;amp;sex" and age in(%eval(&amp;amp;index+10),%eval(&amp;amp;index+11),%eval(&amp;amp;index+12)) then
        output class_&amp;amp;sex._&amp;amp;index;
      %end;
    %end;
  run;
%mend;
%split_data(M F,1 2 3);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 19 Apr 2018 07:40:27 GMT</pubDate>
    <dc:creator>s_lassen</dc:creator>
    <dc:date>2018-04-19T07:40:27Z</dc:date>
    <item>
      <title>Loop a macro through 2 different sets of indices, one of which is staggered</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-a-macro-through-2-different-sets-of-indices-one-of-which-is/m-p/455352#M115166</link>
      <description>&lt;P&gt;I'm running SAS 9.4 TS Level 1M3.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a macro called FILTER_DATA.&amp;nbsp; I use it to create smaller data sets by filtering SASHELP.CLASS.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%macro filter_data(sex, index, age1, age2, age3);

data class_&amp;amp;sex._&amp;amp;index;
     set sashelp.class;&lt;BR /&gt;&lt;BR /&gt;     if sex = "&amp;amp;sex";
    
     if age = &amp;amp;age1 or age= &amp;amp;age2 or age = &amp;amp;age3;
run;

%mend;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My challenge is to loop through many applications of FILTER_DATA.&amp;nbsp; Instead of explaining how I want to loop them, it's easier just to show you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%FILTER_DATA(M, 1, 11, 12, 13);
%FILTER_DATA(M, 2, 12, 13, 14);
%FILTER_DATA(M, 3, 13, 14, 15);


%FILTER_DATA(F,&amp;nbsp;1, 11,&amp;nbsp;12,&amp;nbsp;13);
%FILTER_DATA(F,&amp;nbsp;2, 12,&amp;nbsp;13,&amp;nbsp;14);
%FILTER_DATA(F,&amp;nbsp;3, 13,&amp;nbsp;14,&amp;nbsp;15);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;What code can implement all&amp;nbsp;6 lines in a loop?&lt;/P&gt;</description>
      <pubDate>Wed, 18 Apr 2018 19:25:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-a-macro-through-2-different-sets-of-indices-one-of-which-is/m-p/455352#M115166</guid>
      <dc:creator>PurpleNinja</dc:creator>
      <dc:date>2018-04-18T19:25:06Z</dc:date>
    </item>
    <item>
      <title>Re: Loop a macro through 2 different sets of indices, one of which is staggered</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-a-macro-through-2-different-sets-of-indices-one-of-which-is/m-p/455357#M115168</link>
      <description>If you only have six, you don't need a loop.&lt;BR /&gt;But looping is done via %do within the macro.</description>
      <pubDate>Wed, 18 Apr 2018 18:55:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-a-macro-through-2-different-sets-of-indices-one-of-which-is/m-p/455357#M115168</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2018-04-18T18:55:36Z</dc:date>
    </item>
    <item>
      <title>Re: Loop a macro through 2 different sets of indices, one of which is staggered</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-a-macro-through-2-different-sets-of-indices-one-of-which-is/m-p/455360#M115169</link>
      <description>My data set is actually MUCH bigger than this, and I have hundreds of iterations.&lt;BR /&gt;&lt;BR /&gt;I used SASHELP.CLASS just to illustrate my intention.</description>
      <pubDate>Wed, 18 Apr 2018 19:04:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-a-macro-through-2-different-sets-of-indices-one-of-which-is/m-p/455360#M115169</guid>
      <dc:creator>PurpleNinja</dc:creator>
      <dc:date>2018-04-18T19:04:55Z</dc:date>
    </item>
    <item>
      <title>Re: Loop a macro through 2 different sets of indices, one of which is staggered</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-a-macro-through-2-different-sets-of-indices-one-of-which-is/m-p/455381#M115177</link>
      <description>&lt;P&gt;Create a dataset with your filter value combinations and use call execute from that to execute your macro repeatedly.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Apr 2018 19:53:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-a-macro-through-2-different-sets-of-indices-one-of-which-is/m-p/455381#M115177</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-04-18T19:53:35Z</dc:date>
    </item>
    <item>
      <title>Re: Loop a macro through 2 different sets of indices, one of which is staggered</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-a-macro-through-2-different-sets-of-indices-one-of-which-is/m-p/455382#M115178</link>
      <description>I'm sorry - I don't know how to do that. Could you please show me with some code?&lt;BR /&gt;&lt;BR /&gt;Thank you.</description>
      <pubDate>Wed, 18 Apr 2018 19:56:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-a-macro-through-2-different-sets-of-indices-one-of-which-is/m-p/455382#M115178</guid>
      <dc:creator>PurpleNinja</dc:creator>
      <dc:date>2018-04-18T19:56:19Z</dc:date>
    </item>
    <item>
      <title>Re: Loop a macro through 2 different sets of indices, one of which is staggered</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-a-macro-through-2-different-sets-of-indices-one-of-which-is/m-p/455393#M115186</link>
      <description>&lt;P&gt;CALL EXECUTE. Check Example 2 the documentation for the example.&lt;/P&gt;
&lt;P&gt;Create a data step loop and pass the arguments to the macro that way. A data step loop is easier to manage.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;A href="http://documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=n1q1527d51eivsn1ob5hnz0yd1hx.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank"&gt;http://documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=n1q1527d51eivsn1ob5hnz0yd1hx.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Apr 2018 20:17:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-a-macro-through-2-different-sets-of-indices-one-of-which-is/m-p/455393#M115186</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-04-18T20:17:13Z</dc:date>
    </item>
    <item>
      <title>Re: Loop a macro through 2 different sets of indices, one of which is staggered</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-a-macro-through-2-different-sets-of-indices-one-of-which-is/m-p/455489#M115216</link>
      <description>&lt;P&gt;You can do what you want like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro runit;
  %local sexes index i j sex;
  %let sexes=MF;
  %do index=1 %to 3;
    %do i=1 %to 2;
      %let sex=%substr(&amp;amp;sexes,&amp;amp;i,1);
      %filter_data(&amp;amp;sex,&amp;amp;index,%eval(&amp;amp;index+10),%eval(&amp;amp;index+11),%eval(&amp;amp;index+12));
      %end;
    %end;
%mend;
%runit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But you will get more mileage with large data if you use the conditions to split the data in one datastep, e.g.:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro split_data(sexes,indexes);
  %local i j;
  data
  %do i=1 %to %sysfunc(countw(&amp;amp;sexes));
    %do j=1 %to %sysfunc(countw(&amp;amp;indexes));
      %let sex=%scan(&amp;amp;sexes,&amp;amp;i);
      %let index=%scan(&amp;amp;indexes,&amp;amp;j);
      class_&amp;amp;sex._&amp;amp;index
      %end;
    %end;
    ;
  set sashelp.class;
  %do i=1 %to %sysfunc(countw(&amp;amp;sexes));
    %do j=1 %to %sysfunc(countw(&amp;amp;indexes));
      %let sex=%scan(&amp;amp;sexes,&amp;amp;i);
      %let index=%scan(&amp;amp;indexes,&amp;amp;j);
      if sex="&amp;amp;sex" and age in(%eval(&amp;amp;index+10),%eval(&amp;amp;index+11),%eval(&amp;amp;index+12)) then
        output class_&amp;amp;sex._&amp;amp;index;
      %end;
    %end;
  run;
%mend;
%split_data(M F,1 2 3);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Apr 2018 07:40:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-a-macro-through-2-different-sets-of-indices-one-of-which-is/m-p/455489#M115216</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2018-04-19T07:40:27Z</dc:date>
    </item>
    <item>
      <title>Re: Loop a macro through 2 different sets of indices, one of which is staggered</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-a-macro-through-2-different-sets-of-indices-one-of-which-is/m-p/455618#M115285</link>
      <description>That's incredible - thank you, s_lassen!</description>
      <pubDate>Thu, 19 Apr 2018 14:28:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-a-macro-through-2-different-sets-of-indices-one-of-which-is/m-p/455618#M115285</guid>
      <dc:creator>PurpleNinja</dc:creator>
      <dc:date>2018-04-19T14:28:26Z</dc:date>
    </item>
  </channel>
</rss>

