<?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 macro variables inside an array? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-macro-variables-inside-an-array/m-p/82226#M17753</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks... perfect.&amp;nbsp; I love learning new tricks like this, and there are so many to learn.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 27 Nov 2012 23:14:00 GMT</pubDate>
    <dc:creator>AD</dc:creator>
    <dc:date>2012-11-27T23:14:00Z</dc:date>
    <item>
      <title>Using macro variables inside an array?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-macro-variables-inside-an-array/m-p/82224#M17751</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I've got a dataset (Data1) with a bunch of variables (Var1, Var2, ..., VarN), and I want to be able to specify a number of different "sets" of variables on which I will be performing the same analysis.&amp;nbsp; I'd like to do this inside of a macro, but I need a little guidance.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want the user to be able to specify the number of sets and the variables associated with each set (see below for example):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%LET NumSets = 3;&lt;/P&gt;&lt;P&gt;%LET Set1 = Var1 Var2 Var3;&lt;/P&gt;&lt;P&gt;%LET Set2 = Var8 Var9 Var10;&lt;/P&gt;&lt;P&gt;%LET Set3 = Var12 Var13 Var14 Var15;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I also want to be able to perform a simple analysis (e.g., PROC CORR) for each "set".&amp;nbsp; The number of sets might change from user to user, however.&amp;nbsp; I've got the shell of the macro below, but something needs to be fixed.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro Corr;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do i = 1 to &amp;amp;NumSets;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; proc corr&amp;nbsp; data=Data1;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var Set&amp;amp;i;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can see that in the bolded line above, Proc Corr would be searching for a variable named "Set1" during the first iteration of the do loop.&amp;nbsp; But I don't want it searching for a variable named set1, I want Proc Corr to be analyzing the set of variables that were defined above in the Set1 macro variable.&amp;nbsp; I'm not sure how to get this done.&amp;nbsp; I don't know much about arrays, but maybe that's the right approach?&amp;nbsp; Or perhaps there is a simple shortcut or modification that I could make to that var statement?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Andy&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Nov 2012 19:35:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-macro-variables-inside-an-array/m-p/82224#M17751</guid>
      <dc:creator>AD</dc:creator>
      <dc:date>2012-11-27T19:35:52Z</dc:date>
    </item>
    <item>
      <title>Re: Using macro variables inside an array?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-macro-variables-inside-an-array/m-p/82225#M17752</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;STRONG style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;%macro&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; &lt;STRONG&gt;&lt;EM&gt;Corr&lt;/EM&gt;&lt;/STRONG&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;%do&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; i = &lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;1&lt;/STRONG&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;%to&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; &amp;amp;NumSets;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; proc corr data=Data1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var &amp;amp;&amp;amp;Set&amp;amp;i;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;%end&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;STRONG style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;%mend&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You will need the double ampersands (&amp;amp;&amp;amp;) in front of your Set&amp;amp;i macro.&amp;nbsp; Otherwise, SAS sees the variable as Set1, but there is no variable Set1.&amp;nbsp; It is a macro variable called &amp;amp;Set1.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Nov 2012 19:40:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-macro-variables-inside-an-array/m-p/82225#M17752</guid>
      <dc:creator>djbateman</dc:creator>
      <dc:date>2012-11-27T19:40:44Z</dc:date>
    </item>
    <item>
      <title>Re: Using macro variables inside an array?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-macro-variables-inside-an-array/m-p/82226#M17753</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks... perfect.&amp;nbsp; I love learning new tricks like this, and there are so many to learn.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Nov 2012 23:14:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-macro-variables-inside-an-array/m-p/82226#M17753</guid>
      <dc:creator>AD</dc:creator>
      <dc:date>2012-11-27T23:14:00Z</dc:date>
    </item>
  </channel>
</rss>

