Andrew
Andrew

Reputation: 7778

Do While IF ELSE logic in SAS macros

I am new to SAS. Trying to do simple if-else logic and incorporate it into the loop. Having issues; unable to resolve.

%macro iterate ();
    %let lastCount = 0;
    %let currentCount=0;
    %let infiniteLoop= 1;

%do %while(&infiniteLoop=1); 

/* ..some sql logic */

proc sql noprint;
select count(*) into :currentCount from table1;
quit;

IF &currentCount=&lastCount 
THEN &infiniteLoop=0
ELSE  &lastCount = &currentCount;

%put 'show values: ' &lastCount;
%end;
%mend iterate;

%iterate();
run;

Having errors like "Statement is not valid.

Upvotes: 0

Views: 215

Answers (1)

stallingOne
stallingOne

Reputation: 4006

You need to use %if %then %else instead of if then else

http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a000543542.htm

and use %let to overwrite your macro variables.

like this

    %IF &currentCount=&lastCount %THEN %let infiniteLoop=0 ;
    %ELSE  %let lastCount = &currentCount;

Upvotes: 3

Related Questions