BookmarkSubscribeRSS Feed
Newph
Calcite | Level 5

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;

5 REPLIES 5
ballardw
Super User

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.

 

Newph
Calcite | Level 5

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;

art297
Opal | Level 21

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

 

ballardw
Super User

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.

Sven111
Pyrite | Level 9

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;

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
  • 5 replies
  • 2774 views
  • 0 likes
  • 4 in conversation