Just a note that when you do this:
data new_data_&i;
set test;
Your starting point is always TEST so that your data from the previous iteration does not affect the new iteration. Sometimes that is what you want and sometimes it's not.
Parameters within a macro by definition are local, so defining them as local and re-assigning is redundant
For the FIND function, put the second parameter in quotes as FIND requieres character/string parameters
DO loop needs to be fixed as others have suggested.
%macro test(start=, end=)
%do i = &start %to &end;
data new_data_&i;
set test;
first_result = find(number, "&i", "i");
run;
%end;
%mend test;
%test(start=1,end=8);
@MaxiHösi wrote:
Hello forum,
i have problems using loop statements outside of a data step.
I have this data step and want to run it several times (e.g. 8 times) :
data new_data;
set test;
first_result = find(number, &start, "i");
run;
My variable is &start and i want to define a macro with a range from e.g. 1-8.
I tried it like below, but it doesn't work:
%macro test(start=1, end=8)
%local start end;
%let start=&start;
%let end=&end;
%do &start %to &end;
data new_data_&start;
set test;
first_result = find(number, &start, "i");
run;
%let start=&start+1;
%end;
&mend test;
%test(start=1,end=8);
Thanks for your help in advance.
... View more