BookmarkSubscribeRSS Feed
harithalavu
Calcite | Level 5

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(;));

          %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(;));

          %end;

     then do;

             rules_c="&&trigc&trig_i";

             rules_num=&&trigh&trig_i;

     end;

%end;

2 REPLIES 2
Tom
Super User Tom
Super User

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.

ballardw
Super User

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;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1123 views
  • 0 likes
  • 3 in conversation