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;

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
  • 2 replies
  • 665 views
  • 0 likes
  • 3 in conversation