Macro to loop through variables and store results SAS
<p>I have the following variables: <code>A_Bldg B_Bldg C_Bldg D_Bldg</code>. I want to multiply them by <code>INTSF</code> and store the result in a new variable, <code>Sale_i</code>. For example, <code>A_Bldg * INTSF = Sale_A</code>, <code>B_Bldg * INTSF = Sale_B</code>, and so on. </p>

<p>My code is:</p>

<pre><code>%macro loopit(mylist);
%let n=%sysfunc(countw(&amp;mylist));
%do J = 1 %to &amp;n;
%let i = %scan(&amp;mylist,&amp;J);

  data test;
  set data;
  sale_&amp;i. = &amp;i._Bldg * INTSF;
  run;

%end;
%mend;

%let list = A B C D;
%loopit(&amp;list);
</code></pre>

<p>This only produces <code>Sale_D</code>, which is the last letter in the list. How do I get <code>Sales A-C</code> to appear? The first four lines of code are so I can loop through the text A-D. I thought about doing it with arrays, but didn't know how to choose the variables based on the A-D indicators. Thanks for your help!</p>