BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Quodly
Obsidian | Level 7

 

%macro a(condition);
  %do i = 1 %to %if &condition. %then 2; %else 3;;
    %put &i.;
  %end;
%mend;

 

ERROR: There is no matching %IF statement for the %ELSE.
ERROR: A dummy macro will be compiled.

what is the problem?

 

%macro b(condition);
  %do i = 1 %to %sysfunc(ifn(&condition., 2, 3));
    %put &i.;
  %end;
%mend;

%b(0);
%b(1);
%b(0);
1
2
3
%b(1);
1
2

this seem to work, though.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26


ERROR: There is no matching %IF statement for the %ELSE.

%IF is in a location in a %DO statement where it is not allowed.

 

ERROR: A dummy macro will be compiled.

You macro named %A has not been compiled and so cannot be used.

 

This, however, would work, as now the %IF is in a position where it is recognized. (Your %b is another way to make this work)

 

%macro a(condition);
    %if &condition. %then %let endvalue = 2; 
    %else %let endvalue=3;
    %do i = 1 %to &endvalue;
        %put &i.;
    %end;
%mend;

%a(0)
%a(1)
--
Paige Miller

View solution in original post

1 REPLY 1
PaigeMiller
Diamond | Level 26


ERROR: There is no matching %IF statement for the %ELSE.

%IF is in a location in a %DO statement where it is not allowed.

 

ERROR: A dummy macro will be compiled.

You macro named %A has not been compiled and so cannot be used.

 

This, however, would work, as now the %IF is in a position where it is recognized. (Your %b is another way to make this work)

 

%macro a(condition);
    %if &condition. %then %let endvalue = 2; 
    %else %let endvalue=3;
    %do i = 1 %to &endvalue;
        %put &i.;
    %end;
%mend;

%a(0)
%a(1)
--
Paige Miller

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
  • 1 reply
  • 810 views
  • 1 like
  • 2 in conversation