BookmarkSubscribeRSS Feed
sasuser31
Calcite | Level 5

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

 

2 REPLIES 2
Patrick
Opal | Level 21

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;
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 749 views
  • 0 likes
  • 3 in conversation