DATA Step, Macro, Functions and more

SAS Macro's and Loops

New Contributor
Posts: 2

SAS Macro's and Loops


I am new to SAS and came across some SAS code.It is working fine. But feel difficulty in understanding the flow of SAS code. Could any one explain the flow of this %DO,IF and %DO %WHILE and when IF condition is getting executed with this %DO %WHILE and Macro variables?

%do trig_i=1 %to &trig_count.;

    if 1 eq 1

             %let trig_j=1;

             %let trig=%scan(&&trigc&trig_i,&trig_j,%str(Smiley Wink);

          %do %while(&trig ne %str());

          AND find(rules_comb_org,"&trig;")>0

                    %let trig_j=%eval(&trig_j+1);

                    %let trig=%scan(&&trigc&trig_i,&trig_j,%str(Smiley Wink);


     then do;





Super User
Super User
Posts: 6,498

SAS Macro's and Loops

The macro logic allows you to generate SAS code.  In this case the macro logic is generating IF/THEN/DO/END blocks of statements.  It does this &TRIG_COUNT times.

To see if it will really work you need to see the rest of the macro definition and also the DATA step that these IF statements will be used within.

Super User
Posts: 10,466

SAS Macro's and Loops

One way to see what is going on is to execute the code with OPTIONS MPRINT SYMBOLGEN; in the code.

The log will then show what the macro variables are being evaluated to (SYMBOLGEN) and then what entire lines of generated code looks like (MPRINT). The log will also display the name of the macro executing which is helpful if you have multiple macros in your program.

Turn the options off with OPTIONS NOMPRINT NOSYMBOLGEN;

Ask a Question
Discussion stats
  • 2 replies
  • 3 in conversation