<?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: how to use a list of macro variables? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/how-to-use-a-list-of-macro-variables/m-p/15891#M2851</link>
    <description>Great suggestions, Thanks for the help all!</description>
    <pubDate>Fri, 17 Jun 2011 16:29:28 GMT</pubDate>
    <dc:creator>SASguyCO</dc:creator>
    <dc:date>2011-06-17T16:29:28Z</dc:date>
    <item>
      <title>how to use a list of macro variables?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-use-a-list-of-macro-variables/m-p/15888#M2848</link>
      <description>This is probably a really dumb question, but how in the world do you sum or better yet, use a list of macro variables with just the "-" without having to write out evey single &amp;amp;var_1, &amp;amp;var_2.....&amp;amp;var_i.  I use this all the time for non macro variables, but thought it would be the same for macro variables.  &lt;BR /&gt;
&lt;BR /&gt;
For example:&lt;BR /&gt;
&lt;BR /&gt;
%let var1=1;&lt;BR /&gt;
%let var2=2;&lt;BR /&gt;
%let var3=3;&lt;BR /&gt;
&lt;BR /&gt;
data t;&lt;BR /&gt;
varall=%sysfunc(sum(of &amp;amp;var1-&amp;amp;var3));&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
or even as such:&lt;BR /&gt;
&lt;BR /&gt;
%let dset1=dsn_2011;&lt;BR /&gt;
%let dset2=dsn_2010;&lt;BR /&gt;
%let dset3=dsn_2009;&lt;BR /&gt;
&lt;BR /&gt;
data all;&lt;BR /&gt;
&amp;amp;dset1-&amp;amp;dset3;&lt;BR /&gt;
run;</description>
      <pubDate>Fri, 17 Jun 2011 06:20:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-use-a-list-of-macro-variables/m-p/15888#M2848</guid>
      <dc:creator>SASguyCO</dc:creator>
      <dc:date>2011-06-17T06:20:24Z</dc:date>
    </item>
    <item>
      <title>Re: how to use a list of macro variables?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-use-a-list-of-macro-variables/m-p/15889#M2849</link>
      <description>Hi, &lt;BR /&gt;
&lt;BR /&gt;
Some thoughts on your question: &lt;BR /&gt;
&lt;BR /&gt;
You could create macro variable list (though, this won't work on that sum (of ..) question, as macro variables generated are not numbers but character string):&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
data macro_variables;&lt;BR /&gt;
 input variables $;&lt;BR /&gt;
 datalines;&lt;BR /&gt;
  dsn_2011&lt;BR /&gt;
  dsn_2010&lt;BR /&gt;
  dsn_2009&lt;BR /&gt;
 ;&lt;BR /&gt;
 run;&lt;BR /&gt;
&lt;BR /&gt;
proc sql noprint;&lt;BR /&gt;
  select variables into: macro_var_list separated by ' ' from macro_variables;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
data all;&lt;BR /&gt;
set &amp;amp;macro_var_list;&lt;BR /&gt;
run; &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Another way how to get similar results:&lt;BR /&gt;
&lt;BR /&gt;
%macro collect_data;&lt;BR /&gt;
&lt;BR /&gt;
 data all;&lt;BR /&gt;
   set   %do i=2009 %to 2011;&lt;BR /&gt;
          dsn_&amp;amp;i&lt;BR /&gt;
   %end;;&lt;BR /&gt;
  run;&lt;BR /&gt;
%mend ;&lt;BR /&gt;
%collect_data;&lt;BR /&gt;
&lt;BR /&gt;
Hope it helps or at least gives some ideas to think about! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Fri, 17 Jun 2011 08:21:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-use-a-list-of-macro-variables/m-p/15889#M2849</guid>
      <dc:creator>ieva</dc:creator>
      <dc:date>2011-06-17T08:21:22Z</dc:date>
    </item>
    <item>
      <title>Re: how to use a list of macro variables?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-use-a-list-of-macro-variables/m-p/15890#M2850</link>
      <description>Hi&lt;BR /&gt;
&lt;BR /&gt;
You probabely would solve your first example this way:&lt;BR /&gt;
&lt;BR /&gt;
%let var1=1;&lt;BR /&gt;
%let var2=2;&lt;BR /&gt;
%let var3=3;&lt;BR /&gt;
&lt;BR /&gt;
proc sql noprint;&lt;BR /&gt;
  select cats('&amp;amp;',name) into :MacroVarList separated by ','&lt;BR /&gt;
  from  DICTIONARY.MACROS&lt;BR /&gt;
  where name like 'VAR%';&lt;BR /&gt;
  %put &amp;amp;MacroVarList;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
data _null_;&lt;BR /&gt;
  varall=sum(&amp;amp;MacroVarList);&lt;BR /&gt;
  put varall=;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
And the second one very similar only that the separator would be a blank and not a comma.&lt;BR /&gt;
&lt;BR /&gt;
HTH&lt;BR /&gt;
Patrick</description>
      <pubDate>Fri, 17 Jun 2011 12:14:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-use-a-list-of-macro-variables/m-p/15890#M2850</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2011-06-17T12:14:21Z</dc:date>
    </item>
    <item>
      <title>Re: how to use a list of macro variables?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-use-a-list-of-macro-variables/m-p/15891#M2851</link>
      <description>Great suggestions, Thanks for the help all!</description>
      <pubDate>Fri, 17 Jun 2011 16:29:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-use-a-list-of-macro-variables/m-p/15891#M2851</guid>
      <dc:creator>SASguyCO</dc:creator>
      <dc:date>2011-06-17T16:29:28Z</dc:date>
    </item>
    <item>
      <title>Re: how to use a list of macro variables?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-use-a-list-of-macro-variables/m-p/15892#M2852</link>
      <description>"using a list of macro variables"&lt;BR /&gt;
is close to a thread I worked on earlier&lt;BR /&gt;
"list programming with sas "&lt;BR /&gt;
1 here is a list&lt;BR /&gt;
2 here is a process&lt;BR /&gt;
3 how to  apply the process(=2) to each item in the list (=1)&lt;BR /&gt;
&lt;BR /&gt;
see &lt;BR /&gt;
List Processing - Make Light Work of List Processing in SAS®&lt;BR /&gt;
&lt;A href="http://www2.sas.com/proceedings/sugi31/012-31.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi31/012-31.pdf&lt;/A&gt;</description>
      <pubDate>Fri, 17 Jun 2011 16:35:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-use-a-list-of-macro-variables/m-p/15892#M2852</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2011-06-17T16:35:53Z</dc:date>
    </item>
  </channel>
</rss>

