Macro: if within do loop

Reply
Occasional Contributor
Posts: 13

Macro: if within do loop

Hi I am truing to create a macro with if statement within a do loop but I kept on geeting an error:ERROR: There is no matching %IF statement for the %ELSE.
ERROR: A dummy macro will be compiled.

 

Below is my code, any help woul be greatly appreciated

 

 

%macro test;

%do I=1 %TO 20;
%if &I=1 %then %do;
...
%end;
%else %do;
...
%end;
%END;
%MEND test;
%test;

Grand Advisor
Posts: 10,239

Re: Macro: if within do loop

You need to post you whole code. It is very likely that in the body of your suppressed code (the ...) you have made an error such as not closing a quote, ( or missing a semicolon. The error is typical when one of these happens.

 

Occasional Contributor
Posts: 13

Re: Macro: if within do loop

heres the code--thanks in advance for any help

 

%macro test;

%do I=1 %TO 20;

%if &I=1 %then %do;
proc logistic data = mydata order=internal descending outmodel=outdata;
model &dep =&ind
/MAXITER=1000000;
run;
%end;

%else %do;

proc logistic data = mydata2 order=internal descending outmodel=mydata3;
model &dep =&ind
/MAXITER=1000000;
run;

proc logistic inmodel=mydata3;
score clm data = mydata4 out=mydata5;
run;

%end;

%END;
%MEND test;
%test;

Esteemed Advisor
Posts: 7,299

Re: Macro: if within do loop

For starters, where are the macro variables &dep and &ind set?

 

You don't appear to declare either within your macro.

 

HTH,

Art, CEO, AnalystFinder.com

 

Grand Advisor
Posts: 10,239

Re: Macro: if within do loop

I'm with Art on this. We need to know what the values of &dep and &ind resolve to.

 

I'm going to suspect that something in the IND variable is being created with other code and it actually has part of the code such as %end instead of resolved values to a simple list of variable names.

 

%put dep=&dep  ind=&ind; and show the results.

Frequent Contributor
Posts: 81

Re: Macro: if within do loop

I was able to compile your macro with no problems.  Could you attach the full log?

 

I also modified the code and just replaced the PROC LOGISTIC with a %PUT statement and it compiled and ran for me with no problems.

 

%MACRO TEST;
    %DO I=1 %TO 20;
        %IF &I=1 
        %THEN 
            %DO;
                %PUT &=I;
            %END;

        %ELSE 
            %DO;
                %PUT &=I;
            %END;
    %END;
%MEND TEST;
%TEST;
Ask a Question
Discussion stats
  • 5 replies
  • 173 views
  • 0 likes
  • 4 in conversation