I have a SAS program that dynamically builds a table with a macro like so:
%macro Projection;
%do i=1 %to &number_of_Years;
%Advance_Years;
proc sql;
create table Projection as
select *, Year_&previous_year.*(1+return) as Year_¤t_year.
from Projection;
quit;
%end;
%Mend Projection;
%Projection;
This is a simplified version of my code. The %Advance_Years
macro basically advances ¤t_year
and &previous_year
macro of 1 year. As you can see this table acquires 1 variable per year. The problem is that the number of rows for this table can reach hundreds of thousands and I've seen the execution time skyrocket, reaching hours to complete.
I've tried option compress=yes
and it helped reduce execution time but not a lot. I've tried most of the SAS tips and tricks for speeding up execution but again, not much of a difference. I'm running Base SAS 9.2 on a 32b.
I think I have a wrong take on the variable adding technique. Does the fact that I overwrite my table on each loop have an effect on execution efficiency ? If yes how could I rewrite this to be the MOST efficient code possible ? Please bear in mind that I cannot 'transpose' the table and just add more rows. Thanks in advance!