so i have coded thousands of macro variables each containing a if statement that i need to process in a data step.
ideally, i can just make 1 macro and run it. however, it's too big for 1 macro variable to handle.
so i have no choice but to create thousands.
so how do i call each of the macro variable in 1 data step?
right now, i am doing a loop which will call 1 macro at a time but it's just terrible inefficient.
example,
%do i=1 %to &count %by 1;
data step;
set step;
¯o&i;
run;
%end;
something like this.
how can i make this into 1 data step and run all macro variables within?
thanks a bunch.
The ineffciency comes from reading the same data for each of your if statements. You should code it like this:
%macro test;
data step;
set step;
%do i=1 %to &count %by 1;
¯o&i;
%end;
run;
%mend;
%test
In this way the macro will generate all the IF statements in one DATA Step and the data is only red once.
Bruno
Can you change your design to use DOSUBL or %include code from a text file?
Can you post a small example of what you're process is so we can make better suggestion for improvement or alternatives?
@Grumbler wrote:
so i have coded thousands of macro variables each containing a if statement that i need to process in a data step.
ideally, i can just make 1 macro and run it. however, it's too big for 1 macro variable to handle.
so i have no choice but to create thousands.
so how do i call each of the macro variable in 1 data step?
right now, i am doing a loop which will call 1 macro at a time but it's just terrible inefficient.
example,
%do i=1 %to &count %by 1;
data step;
set step;
¯o&i;
run;
%end;
something like this.
how can i make this into 1 data step and run all macro variables within?
thanks a bunch.
The ineffciency comes from reading the same data for each of your if statements. You should code it like this:
%macro test;
data step;
set step;
%do i=1 %to &count %by 1;
¯o&i;
%end;
run;
%mend;
%test
In this way the macro will generate all the IF statements in one DATA Step and the data is only red once.
Bruno
I would really be suprised if the use of thousands of macro variables is the best method to process data. Base SAS is the executable language for processing data, and is fully functional, macro does not do anything other than generate this code. If you can provide some examples I can show better methods to get the output. For example there is data modelling, i.e. restructuring data to make coding more efficient - one thing I always see is the "Excel" mentality, having data going across the page which is ok for people to look at, but sub optimal to program with. Next there is lots of functionality within the base langauge to perform various functions against arrays of variables and over numbers of rows.
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.