<?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: Using a do loop to create a macro array instead of using %LET in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-a-do-loop-to-create-a-macro-array-instead-of-using-LET/m-p/432935#M281818</link>
    <description>&lt;P&gt;How about?:&lt;/P&gt;
&lt;PRE&gt;data _null_;
  length years $255;
  do y = 1901 to 1903;
    year=catt('YEAR_',y);
    years=catx(' ',years,year);
  end;
  call symput('DB',years);
run;
%put &amp;amp;db.;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 31 Jan 2018 22:42:56 GMT</pubDate>
    <dc:creator>art297</dc:creator>
    <dc:date>2018-01-31T22:42:56Z</dc:date>
    <item>
      <title>Using a do loop to create a macro array instead of using %LET</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-do-loop-to-create-a-macro-array-instead-of-using-LET/m-p/432921#M281817</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am&amp;nbsp;querying an online database which has monthly tables (with the month's date in the table's name, e.g.&amp;nbsp;"MONTH_201701"). I want to query all those tables in a do loop. A friend has been able to find relevant information in the &lt;A href="http://www2.sas.com/proceedings/forum2008/105-2008.pdf" target="_self"&gt;following document&lt;/A&gt;. Basically, by using the following macro variable containing all the table names, the loop now manages to query all those tables. What I am trying to do now is create this variable automatically by using a span of dates (assuming I want all 12 months in a year).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The way the script works now is by having the following line, which I am hoping to replace by a call to a macro with the years as parameters:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%LET DB = YEAR_1901 YEAR_1902 YEAR_1903; /* etc. */&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I would like is for the db variable to be created automatically&amp;nbsp;by a call such as:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;&lt;BR /&gt;    do y = 1901 to 1903;&lt;BR /&gt;        %let DB = cat( ' ', &amp;amp;DB, compress( 'YEAR_'!!y ) );&lt;BR /&gt;    end;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data _null_;&lt;BR /&gt;    put &amp;amp;DB;&lt;BR /&gt;run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This syntax is incorrect, but my ambition is&amp;nbsp;that since the names of the tables&amp;nbsp;follow an algorithm to simply use that algorithm to create the list of names without having to input them manually.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sylvain.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2018 21:31:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-do-loop-to-create-a-macro-array-instead-of-using-LET/m-p/432921#M281817</guid>
      <dc:creator>scardinet</dc:creator>
      <dc:date>2018-01-31T21:31:35Z</dc:date>
    </item>
    <item>
      <title>Re: Using a do loop to create a macro array instead of using %LET</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-do-loop-to-create-a-macro-array-instead-of-using-LET/m-p/432935#M281818</link>
      <description>&lt;P&gt;How about?:&lt;/P&gt;
&lt;PRE&gt;data _null_;
  length years $255;
  do y = 1901 to 1903;
    year=catt('YEAR_',y);
    years=catx(' ',years,year);
  end;
  call symput('DB',years);
run;
%put &amp;amp;db.;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2018 22:42:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-do-loop-to-create-a-macro-array-instead-of-using-LET/m-p/432935#M281818</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2018-01-31T22:42:56Z</dc:date>
    </item>
    <item>
      <title>Re: Using a do loop to create a macro array instead of using %LET</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-do-loop-to-create-a-macro-array-instead-of-using-LET/m-p/432941#M281819</link>
      <description>&lt;P&gt;Maybe you don't need macros.&lt;/P&gt;
&lt;P&gt;Look at this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%*create monthly data;
data D_191601 D_191602 D_191603 D_191604;
  X=1;
run;

%*gather all months;
data _V/view=_V; 
  set D_191601-D_191604 indsname=INDSNAME;
  MONTH=compress(INDSNAME,,'dk');
run;

%*analyse by month;
proc means data=_V;
  by MONTH;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 31 Jan 2018 23:28:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-do-loop-to-create-a-macro-array-instead-of-using-LET/m-p/432941#M281819</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-01-31T23:28:02Z</dc:date>
    </item>
    <item>
      <title>Re: Using a do loop to create a macro array instead of using %LET</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-do-loop-to-create-a-macro-array-instead-of-using-LET/m-p/432943#M281820</link>
      <description>&lt;P&gt;Or maybe you can manage your macro loop without that string:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%macro analyse(table);
  proc print; run;
%mend;

%macro loop;
  %local i;
  %do i=191601 %to 191812;
    %if %sysfunc(exist(D_&amp;amp;i.)) %then %analyse(D_&amp;amp;i.);
  %end;
%mend;
%loop&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 31 Jan 2018 23:34:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-do-loop-to-create-a-macro-array-instead-of-using-LET/m-p/432943#M281820</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-01-31T23:34:38Z</dc:date>
    </item>
    <item>
      <title>Re: Using a do loop to create a macro array instead of using %LET</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-do-loop-to-create-a-macro-array-instead-of-using-LET/m-p/432957#M281821</link>
      <description>&lt;P&gt;This worked immediately, thanks !! I will leave more feedback regarding the other answers as well as, possibly, there might be a better way to do this code as a whole (I mean my whole macro thing is perhaps inefficient). But as I am time-constrained, just plugging this solution into my code worked like a charm &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2018 00:58:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-do-loop-to-create-a-macro-array-instead-of-using-LET/m-p/432957#M281821</guid>
      <dc:creator>scardinet</dc:creator>
      <dc:date>2018-02-01T00:58:40Z</dc:date>
    </item>
    <item>
      <title>Re: Using a do loop to create a macro array instead of using %LET</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-do-loop-to-create-a-macro-array-instead-of-using-LET/m-p/432959#M281822</link>
      <description>&lt;P&gt;ChrisNZ, thanks for your replies. I accepted the other solution because it was the simplest&amp;nbsp;way to just plug in some code and have it work. However, I realize that your answers open new directions to make my part of the code more maintainable than my&amp;nbsp;current macro. I appreciate the time you took to make those suggestions and I hope to be able to try them out as soon as I have a bit more time.&lt;/P&gt;&lt;P&gt;Cheers &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2018 01:01:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-do-loop-to-create-a-macro-array-instead-of-using-LET/m-p/432959#M281822</guid>
      <dc:creator>scardinet</dc:creator>
      <dc:date>2018-02-01T01:01:56Z</dc:date>
    </item>
  </channel>
</rss>

