DATA Step, Macro, Functions and more

SAS Macro's and Loops

Reply
New Contributor
Posts: 2

SAS Macro's and Loops

Hi,

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 loops....how 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);

          %end;

     then do;

             rules_c="&&trigc&trig_i";

             rules_num=&&trigh&trig_i;

     end;

%end;

Super User
Super User
Posts: 7,039

SAS Macro's and Loops

Posted in reply to harithalavu

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: 11,343

SAS Macro's and Loops

Posted in reply to harithalavu

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
  • 126 views
  • 0 likes
  • 3 in conversation