DATA Step, Macro, Functions and more

Why doesnt decremental macro loop work?

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 5
Accepted Solution

Why doesnt decremental macro loop work?

Hi,

I am writing a %do loop with decreasing iterative value. But this doesn't work. Can anyone help?

%macro loop;

%do i=3 %to 1 by -1;

data b_&i.;

set a&i.;

run;

%end;

%mend;


%loop;


ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: 1 by -1

ERROR: The %TO value of the %DO I loop is invalid.

ERROR: The macro LOOP will stop executing.


Accepted Solutions
Solution
‎09-27-2014 12:35 AM
Super User
Posts: 19,789

Re: Why doesnt decremental macro loop work?

Use %by rather than just by in your do loop statement.

%macro loop;

%do i=3 %to 1 %by -1;

data b_&i.;

set a&i.;

run;

%end;

%mend;


%loop;

View solution in original post


All Replies
Solution
‎09-27-2014 12:35 AM
Super User
Posts: 19,789

Re: Why doesnt decremental macro loop work?

Use %by rather than just by in your do loop statement.

%macro loop;

%do i=3 %to 1 %by -1;

data b_&i.;

set a&i.;

run;

%end;

%mend;


%loop;

Occasional Contributor
Posts: 5

Re: Why doesnt decremental macro loop work?

That worked. Thank you Smiley Happy

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 169 views
  • 0 likes
  • 2 in conversation