I have the following variables: A_Bldg B_Bldg C_Bldg D_Bldg
. I want to multiply them by INTSF
and store the result in a new variable, Sale_i
. For example, A_Bldg * INTSF = Sale_A
, B_Bldg * INTSF = Sale_B
, and so on.
My code is:
%macro loopit(mylist);
%let n=%sysfunc(countw(&mylist));
%do J = 1 %to &n;
%let i = %scan(&mylist,&J);
data test;
set data;
sale_&i. = &i._Bldg * INTSF;
run;
%end;
%mend;
%let list = A B C D;
%loopit(&list);
This only produces Sale_D
, which is the last letter in the list. How do I get Sales A-C
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!