<?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: Multiple Macro Variables in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Multiple-Macro-Variables/m-p/118626#M32733</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks, Quentin! %Gobal was the key. Now the macro works!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 22 Feb 2013 17:14:12 GMT</pubDate>
    <dc:creator>Ilgar</dc:creator>
    <dc:date>2013-02-22T17:14:12Z</dc:date>
    <item>
      <title>Multiple Macro Variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Multiple-Macro-Variables/m-p/118621#M32728</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a long list of macro variables that need to be updated periodically. The values always increase in increments of 7. How can I make this more efficient? So, instead of updating this list manually (I have several other lists that are much longer), can I assign the 1&lt;SUP&gt;st&lt;/SUP&gt; value and then have a DO loop do the job? I tried writing a Macro, but failed each time.&lt;/P&gt;&lt;P&gt;thank you&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue;"&gt;%LET&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt; WK1 = 19392;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue;"&gt;%LET&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt; WK2 = 19399;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue;"&gt;%LET&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt; WK3 = 19406;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue;"&gt;%LET&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt; WK4 = 19413;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue;"&gt;%LET&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt; WK5 = 19420;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt;----------------&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue;"&gt;%LET&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt; WK27 = 19574;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 22 Feb 2013 16:08:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Multiple-Macro-Variables/m-p/118621#M32728</guid>
      <dc:creator>Ilgar</dc:creator>
      <dc:date>2013-02-22T16:08:03Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple Macro Variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Multiple-Macro-Variables/m-p/118622#M32729</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can write a loop in a data _null_ step or change your current code to feed off the first variable. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;start=19392;&lt;/P&gt;&lt;P&gt;do i=1 to 27;&lt;/P&gt;&lt;P&gt;call symput("wk"||strip(put(i, 8.)), start+(i-1)*7);&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let wk1=19392;&lt;/P&gt;&lt;P&gt;%let wk2=%eval(&amp;amp;wk1+7);&lt;/P&gt;&lt;P&gt;%let wk3=%eval(&amp;amp;wk2+7);&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 22 Feb 2013 16:21:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Multiple-Macro-Variables/m-p/118622#M32729</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2013-02-22T16:21:39Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple Macro Variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Multiple-Macro-Variables/m-p/118623#M32730</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You could use Fareeza's approach but, since you mentioned that you were trying to do it with a macro, you could use something like:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro buildit(start);&lt;/P&gt;&lt;P&gt;&amp;nbsp; %do i=1 %to 27;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %LET WK&amp;amp;i = %eval(&amp;amp;start.+(&amp;amp;i-1)*7);&lt;/P&gt;&lt;P&gt;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;%mend buildit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%buildit(19392)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 22 Feb 2013 16:23:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Multiple-Macro-Variables/m-p/118623#M32730</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2013-02-22T16:23:31Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple Macro Variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Multiple-Macro-Variables/m-p/118624#M32731</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you so much, guys!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Reeza, your code worked fine. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Arthur, the macro did not work.&amp;nbsp; I am getting an error message. Does it work when you test it? I would very much like to make it work thru Macro. thanks again.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 22 Feb 2013 16:39:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Multiple-Macro-Variables/m-p/118624#M32731</guid>
      <dc:creator>Ilgar</dc:creator>
      <dc:date>2013-02-22T16:39:46Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple Macro Variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Multiple-Macro-Variables/m-p/118625#M32732</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Art's macro works for me (log below).&amp;nbsp; What error are you getting?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;One think to keep in mind is the *scope* of macro variables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When you call the macro below, it creates local macro variables that will only exist while %buildit is executing (assuming that the macro variables do not already exist in an outer scope).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So if you want the macro variables to be available outside of the macro, you may want to define them as %global, or create them in the outer scope. To make them global, add %global wk&amp;amp;i; inside the %do loop, before the %LET statement. But global macro variables can become problematic/difficult to manage, as they exist for the entire session.&amp;nbsp; May be safer to take Art's do loop and move it inside of the macro you are building.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;85&amp;nbsp;&amp;nbsp; %macro buildit(start);
86&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %do i=1 %to 27;
87&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %LET WK&amp;amp;i = %eval(&amp;amp;start.+(&amp;amp;i-1)*7);
88&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %put WK&amp;amp;i=&amp;amp;&amp;amp;Wk&amp;amp;i;
89&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;
90&amp;nbsp;&amp;nbsp; %mend buildit;
91
92&amp;nbsp;&amp;nbsp; %buildit(19392)
WK1=19392
WK2=19399
WK3=19406
WK4=19413
WK5=19420
WK6=19427
WK7=19434
WK8=19441
WK9=19448
WK10=19455
WK11=19462
WK12=19469
WK13=19476
WK14=19483
WK15=19490
WK16=19497
WK17=19504
WK18=19511
WK19=19518
WK20=19525
WK21=19532
WK22=19539
WK23=19546
WK24=19553
WK25=19560
WK26=19567
WK27=19574
&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;HTH,&lt;/P&gt;&lt;P&gt;--Q.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 22 Feb 2013 17:03:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Multiple-Macro-Variables/m-p/118625#M32732</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2013-02-22T17:03:41Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple Macro Variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Multiple-Macro-Variables/m-p/118626#M32733</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks, Quentin! %Gobal was the key. Now the macro works!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 22 Feb 2013 17:14:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Multiple-Macro-Variables/m-p/118626#M32733</guid>
      <dc:creator>Ilgar</dc:creator>
      <dc:date>2013-02-22T17:14:12Z</dc:date>
    </item>
  </channel>
</rss>

