<?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 Create Macro variable from array in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-Macro-variable-from-array/m-p/423026#M104005</link>
    <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to&amp;nbsp;set up a SAS EG project&amp;nbsp;where multiple macro variables are create at the beginning of the project. These variables are A, A1, A2, A3, A4 and must obey the following rules:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;A is introduced by the user and must be an integer between 1 and 13&lt;/LI&gt;&lt;LI&gt;A1 = A-1; A2=A-2 ....&lt;/LI&gt;&lt;LI&gt;if any of the variables is below 1 than it should go from 13 backwords&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I define A using a prompt and All the rules are defined so my problem is with the other variables that depende on A.&amp;nbsp;&lt;/P&gt;&lt;P&gt;In python I would just use a list and define the variables using negative indexes. Is any way to do this in SAS other than programming a condition for each variable?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 21 Dec 2017 10:17:59 GMT</pubDate>
    <dc:creator>Ricardo_Neves</dc:creator>
    <dc:date>2017-12-21T10:17:59Z</dc:date>
    <item>
      <title>Create Macro variable from array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-Macro-variable-from-array/m-p/423026#M104005</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to&amp;nbsp;set up a SAS EG project&amp;nbsp;where multiple macro variables are create at the beginning of the project. These variables are A, A1, A2, A3, A4 and must obey the following rules:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;A is introduced by the user and must be an integer between 1 and 13&lt;/LI&gt;&lt;LI&gt;A1 = A-1; A2=A-2 ....&lt;/LI&gt;&lt;LI&gt;if any of the variables is below 1 than it should go from 13 backwords&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I define A using a prompt and All the rules are defined so my problem is with the other variables that depende on A.&amp;nbsp;&lt;/P&gt;&lt;P&gt;In python I would just use a list and define the variables using negative indexes. Is any way to do this in SAS other than programming a condition for each variable?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Dec 2017 10:17:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-Macro-variable-from-array/m-p/423026#M104005</guid>
      <dc:creator>Ricardo_Neves</dc:creator>
      <dc:date>2017-12-21T10:17:59Z</dc:date>
    </item>
    <item>
      <title>Re: Create Macro variable from array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-Macro-variable-from-array/m-p/423045#M104011</link>
      <description>&lt;P&gt;Please tell us more on what is the purpose of creating these macro variables, what are they used for.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To process something within a loop you need to create a macro program, the code below shows an example that creates as many macro variables as you need with the proper content.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note, that once you have a global macro variable, it is there to stayin your SAS session, unless you delete them using %SYMDEL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let a = 10;

%macro createVars;
  %local i;
  %do i = 1 %to &amp;amp;a;
    %global a&amp;amp;i;
    %let a&amp;amp;i = &amp;amp;i;
  %end;
%mend;

%createVars

%put _user_;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Dec 2017 10:45:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-Macro-variable-from-array/m-p/423045#M104011</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2017-12-21T10:45:15Z</dc:date>
    </item>
    <item>
      <title>Re: Create Macro variable from array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-Macro-variable-from-array/m-p/423059#M104015</link>
      <description>&lt;P&gt;Macro is really not the best methodolgy.&amp;nbsp; Macro is nothing more than a text find/replace system.&amp;nbsp; Its not good to try to use it for data processing.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What purpose is there in a having X amount of&amp;nbsp;&lt;STRONG&gt;text&lt;/STRONG&gt; macro variables which essentially hold something as simple as the formula?&lt;/P&gt;
&lt;P&gt;Have your prompt supply A.&amp;nbsp; Then whenever you want to use it, the formula is simply &amp;amp;A. - x where x is the iterator in question.&amp;nbsp; There seems no logical reason to keep each evaluated version.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Dec 2017 11:34:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-Macro-variable-from-array/m-p/423059#M104015</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-12-21T11:34:30Z</dc:date>
    </item>
    <item>
      <title>Re: Create Macro variable from array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-Macro-variable-from-array/m-p/423072#M104022</link>
      <description>Hi, This project will run in cycles (13 each year), and in some processes I have to check the results of previous cycles (sometimes up to 4 cycles back). For that I defined these variables so that every time I run the project it will automatically find the tables marked as the previous cycle (for example we are now on cylce 13 so I need to check some info from cycle 12, 11, 10...).&lt;BR /&gt;Since will be starting a new year, this will reset, so in January will start cycle 1 of 2018, but I still need to check cycles 13, 12, 11 and 10 of 2017, and when a cycle 2 starts I need cycle 1 of 2018, 1, 13, 12 ,11.&lt;BR /&gt;&lt;BR /&gt;What I want is for the variables A1, A2 A3 to update automatically when I define A.</description>
      <pubDate>Thu, 21 Dec 2017 12:04:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-Macro-variable-from-array/m-p/423072#M104022</guid>
      <dc:creator>Ricardo_Neves</dc:creator>
      <dc:date>2017-12-21T12:04:14Z</dc:date>
    </item>
    <item>
      <title>Re: Create Macro variable from array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-Macro-variable-from-array/m-p/423081#M104023</link>
      <description>&lt;P&gt;Something like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let a = 2;
data _null_;
a = &amp;amp;a;
do i = 1 to 13;
   a = ifn(a - 1 le 0, 13, a - 1);
   call symputx(cats('a', i), a);
   end;
run;
%put _user_;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Dec 2017 13:03:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-Macro-variable-from-array/m-p/423081#M104023</guid>
      <dc:creator>WarrenKuhfeld</dc:creator>
      <dc:date>2017-12-21T13:03:19Z</dc:date>
    </item>
    <item>
      <title>Re: Create Macro variable from array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-Macro-variable-from-array/m-p/423104#M104028</link>
      <description>&lt;P&gt;Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16777"&gt;@WarrenKuhfeld&lt;/a&gt; I used your code and modified it a bit to fit my purpose.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the final version&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let Alist =1 2 3 4 5 7 8 9 10 11 12 13;
%let A = 1;

data _null_ (drop=i);
array A(4);
do i=1 to 4;
A{i} = scan("&amp;amp;Alist.",ifn(&amp;amp;A-i le 0,&amp;amp;A-i-1,&amp;amp;A-i));
call symputx(cats('A',i),A(i));
end;
run;

%put _user_;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Dec 2017 14:59:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-Macro-variable-from-array/m-p/423104#M104028</guid>
      <dc:creator>Ricardo_Neves</dc:creator>
      <dc:date>2017-12-21T14:59:24Z</dc:date>
    </item>
    <item>
      <title>Re: Create Macro variable from array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-Macro-variable-from-array/m-p/423106#M104029</link>
      <description>&lt;P&gt;OK. Glad I could help.&amp;nbsp; I am not sure why you are using arrays.&amp;nbsp; You certainly don't need to ever drop a variable with&amp;nbsp;DATA _NULL_.&amp;nbsp; The whole point of DATA _NULL_ is you are not making a data set.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Dec 2017 15:07:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-Macro-variable-from-array/m-p/423106#M104029</guid>
      <dc:creator>WarrenKuhfeld</dc:creator>
      <dc:date>2017-12-21T15:07:35Z</dc:date>
    </item>
    <item>
      <title>Re: Create Macro variable from array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-Macro-variable-from-array/m-p/423109#M104030</link>
      <description>Yes you're right ,for this particular case it is not necessary, but I will have to do other calculations inside the loop using the obtained value. That is why I'm using them</description>
      <pubDate>Thu, 21 Dec 2017 15:10:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-Macro-variable-from-array/m-p/423109#M104030</guid>
      <dc:creator>Ricardo_Neves</dc:creator>
      <dc:date>2017-12-21T15:10:58Z</dc:date>
    </item>
    <item>
      <title>Re: Create Macro variable from array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-Macro-variable-from-array/m-p/423161#M104032</link>
      <description>&lt;P&gt;You could easily generate the macro variables using a data step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
 do i=1 to 13 ;
   result=&amp;amp;a-i+13*(&amp;amp;a&amp;lt;=i);
   put i= result= ;
   call symputx(cats('a',i),result);
 end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But how are you using these 13 extra macro variables?&amp;nbsp; Perhaps it would just be easier to create a macro to emit the relative number you need instead of making a bunch of macro variables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro relative(x);
%eval(&amp;amp;a-&amp;amp;x+13*(&amp;amp;a&amp;lt;=&amp;amp;x))
%mend relative ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then instead of referencing &amp;amp;A4 you could reference %RELATIVE(4).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Dec 2017 16:56:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-Macro-variable-from-array/m-p/423161#M104032</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-12-21T16:56:19Z</dc:date>
    </item>
  </channel>
</rss>

