Help using Base SAS procedures

referencing array variables from macros

Reply
Contributor
Posts: 47

referencing array variables from macros

array time_interval{4}$ 10 ('month','month3','annual','ytd');
do i=1 to 4;
%get_calcs(time_interval{i});
end;

Hi all,

In the abover code the macro get_calcs appends variables with month or whichever name you parse onto it (and it works when i send it when individually typed as month, month3 etc.). However, when I use the array it takes it to be the literal array name instead of value. How do I get arround this?

Thanks,
Sachin
p.s. I do know that this has a lot to do with the fact that macros are invoked before the rest of the code. I just want a work around preferably using arrays.
New Contributor
Posts: 3

Re: referencing array variables from macros

Hi Sachin,

Yes you are correct in that the macro processor processes the macro before the data step compiler. As such you need to use the data step routine, call execute to invoke your macro instead.

The following code should do what you want...

array time_interval{4}$ 10 ('month','month3','annual','ytd');
do i=1 to 4;
call execute('%get_calcs(' || time_interval{i} || ')');
end;

I hope this helps.

Cheers,
Michelle
Contributor
Posts: 47

Re: referencing array variables from macros

Hi Michelle,

It helped to some extent. The problem being that call execute waits till data step is finished running, where my variables are no longer in scope. If you want to follow up the error I've posted my new error on:
http://support.sas.com/forums/thread.jspa?threadID=11674&tstart=0

Regardless, thanks for your help. Seems like its on the right track though.
Sachin
Ask a Question
Discussion stats
  • 2 replies
  • 101 views
  • 0 likes
  • 2 in conversation