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.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.