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;

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