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

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 1 reply
  • 458 views
  • 1 like
  • 2 in conversation