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

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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