BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Grumbler
Obsidian | Level 7

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;

 &macro&i;

run;

%end;

 

something like this.

how can i make this into 1 data step and run all macro variables within?

 

thanks a bunch.

1 ACCEPTED SOLUTION

Accepted Solutions
BrunoMueller
SAS Super FREQ

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;
      &macro&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

View solution in original post

4 REPLIES 4
Reeza
Super User

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;

 &macro&i;

run;

%end;

 

something like this.

how can i make this into 1 data step and run all macro variables within?

 

thanks a bunch.


 

BrunoMueller
SAS Super FREQ

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;
      &macro&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

Grumbler
Obsidian | Level 7
thanks everyone. problem solved. forgot about using macro loops inside the data step. 🙂
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.  

sas-innovate-2024.png

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.

 

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
  • 4 replies
  • 1199 views
  • 1 like
  • 4 in conversation