<?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: Macros and Arrays - Is there an easier way to loop through a list in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Macros-and-Arrays-Is-there-an-easier-way-to-loop-through-a-list/m-p/306098#M60964</link>
    <description>&lt;P&gt;Is the list of years the same for every state?&amp;nbsp; If so, then it should be straight forward to add some %DO loops in your macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So instead of calling it once for each freq, you could call it like:&lt;/P&gt;
&lt;P&gt;%test (st=NY VA RI, startyear=2011, stopyear=2013)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That doesn't change the execution efficiency, but it does make it easier to generate the set of PROC FREQ steps without writing each macro call yourself.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another option would be to have a dataset that has one record per freq table you want, with variables State and Year.&amp;nbsp; Then you can use that dataset to drive your macro.&amp;nbsp; For example, using CALL EXECUTE to read a record from the dataset and generate a macro call.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Even if there are millions of records, I'd still consider putting them all together and indexing the dataset.&lt;/P&gt;</description>
    <pubDate>Thu, 20 Oct 2016 21:02:07 GMT</pubDate>
    <dc:creator>Quentin</dc:creator>
    <dc:date>2016-10-20T21:02:07Z</dc:date>
    <item>
      <title>Macros and Arrays - Is there an easier way to loop through a list</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macros-and-Arrays-Is-there-an-easier-way-to-loop-through-a-list/m-p/306082#M60957</link>
      <description>&lt;P&gt;I have a macro that reads&amp;nbsp;through a list of states and years, however, I'm wondering if there's a more efficient way to read through the states instead of only using a macro.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%macro test (st=,year=);

proc freq data=data.out_&amp;amp;st._&amp;amp;year.;
tables place;
run;
%mend test;
%test (st=NY, year=2011);
%test (st=NY, year=2012);
%test (st=NY, year=2013);
%test (st=VA, year=2011);

etc.&lt;/PRE&gt;&lt;P&gt;Is there an easier, more consise way to run through the years without having to have three lines for NY for each year? &amp;nbsp;Should I use an array?&lt;/P&gt;</description>
      <pubDate>Thu, 20 Oct 2016 20:38:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macros-and-Arrays-Is-there-an-easier-way-to-loop-through-a-list/m-p/306082#M60957</guid>
      <dc:creator>einstein</dc:creator>
      <dc:date>2016-10-20T20:38:51Z</dc:date>
    </item>
    <item>
      <title>Re: Macros and Arrays - Is there an easier way to loop through a list</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macros-and-Arrays-Is-there-an-easier-way-to-loop-through-a-list/m-p/306088#M60959</link>
      <description>&lt;P&gt;Why is your data split like that in the first place?&lt;/P&gt;
&lt;P&gt;Perhaps combining them from the start would help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Unless your datasets are in the millions of rows each or possibly tens, there isn't a need to separate the data like that.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Oct 2016 20:45:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macros-and-Arrays-Is-there-an-easier-way-to-loop-through-a-list/m-p/306088#M60959</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-10-20T20:45:31Z</dc:date>
    </item>
    <item>
      <title>Re: Macros and Arrays - Is there an easier way to loop through a list</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macros-and-Arrays-Is-there-an-easier-way-to-loop-through-a-list/m-p/306092#M60961</link>
      <description>&lt;P&gt;Yep, these datasets have millions of observations, which is why they're split by state and year.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Oct 2016 20:52:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macros-and-Arrays-Is-there-an-easier-way-to-loop-through-a-list/m-p/306092#M60961</guid>
      <dc:creator>einstein</dc:creator>
      <dc:date>2016-10-20T20:52:07Z</dc:date>
    </item>
    <item>
      <title>Re: Macros and Arrays - Is there an easier way to loop through a list</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macros-and-Arrays-Is-there-an-easier-way-to-loop-through-a-list/m-p/306098#M60964</link>
      <description>&lt;P&gt;Is the list of years the same for every state?&amp;nbsp; If so, then it should be straight forward to add some %DO loops in your macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So instead of calling it once for each freq, you could call it like:&lt;/P&gt;
&lt;P&gt;%test (st=NY VA RI, startyear=2011, stopyear=2013)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That doesn't change the execution efficiency, but it does make it easier to generate the set of PROC FREQ steps without writing each macro call yourself.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another option would be to have a dataset that has one record per freq table you want, with variables State and Year.&amp;nbsp; Then you can use that dataset to drive your macro.&amp;nbsp; For example, using CALL EXECUTE to read a record from the dataset and generate a macro call.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Even if there are millions of records, I'd still consider putting them all together and indexing the dataset.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Oct 2016 21:02:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macros-and-Arrays-Is-there-an-easier-way-to-loop-through-a-list/m-p/306098#M60964</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2016-10-20T21:02:07Z</dc:date>
    </item>
    <item>
      <title>Re: Macros and Arrays - Is there an easier way to loop through a list</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macros-and-Arrays-Is-there-an-easier-way-to-loop-through-a-list/m-p/306407#M61010</link>
      <description>Thank you! This worked perfectly!</description>
      <pubDate>Fri, 21 Oct 2016 18:31:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macros-and-Arrays-Is-there-an-easier-way-to-loop-through-a-list/m-p/306407#M61010</guid>
      <dc:creator>einstein</dc:creator>
      <dc:date>2016-10-21T18:31:32Z</dc:date>
    </item>
  </channel>
</rss>

