So I feel like I am one step away from getting this to work, but I don think I am understanding correctly how to call a macro array into a normal data statement. I created a statement that stored values (frequencies of a variable) into what I assume is a macro array through this command:
PROC SQL noprint;
select Frequency
into :f1- :f40
from work.freqout2
;quit;
%Let dim_freq = &SqlObs.;
Now I want to use that macro array in a normal data statement...but I am completely lost in how to do so. Here is what I have so far:
data relative_att2;
set relative_att;
array V{*} V_01--V_40;
array V_new {40};
array F{*};
V_total=0;
if totaltypes>1 then do i=1 to 40;
if V{i}~=. then do ;
V_total=V_total+(V{i}*F{i});
end;
v_new{i}=v{i}/v_total;
end;
run;
I need the f array to be those values I stored in the sql statment above(f1--f40)...any help??
I believe it would be better to do this without macro variables like in code below.
data freqout2;
do frequency=1 to 10;
output;
end;
run;
proc transpose data=freqout2 out=freq_trans(keep=Freq_:) prefix=Freq_;
var frequency;
run;
data relative_att2;
set relative_att;
if _n_=1 then set freq_trans;
array V{*} V_01--V_40;
array V_new {40};
array F{*} Freq_:;
V_total=0;
if totaltypes>1 then
do i=1 to 40;
if V{i}~=. then
do;
V_total=V_total+(V{i}*F{i});
end;
v_new{i}=v{i}/v_total;
end;
run;
There is no such thing as a macro array. Macro is a text generation tools, it only has string construct. Use Base SAS which is the programming language. Question, why do you need the values transposed? Show example test data (in the form of a datastep), and required output.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.