DATA Step, Macro, Functions and more

Trying to use macro arrays

Reply
Occasional Contributor
Posts: 15

Trying to use macro arrays

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??

 

Respected Advisor
Posts: 3,891

Re: Trying to use macro arrays

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;
Super User
Super User
Posts: 7,401

Re: Trying to use macro arrays

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.

Ask a Question
Discussion stats
  • 2 replies
  • 200 views
  • 0 likes
  • 3 in conversation