|
Thanks Harry and Dennis,
The first solution listed below, albeit workable, would require nesting
macro definitions, which I understand (from Carpenter's Guide) is
generally considered bad form since the inner definition is apparently
recompiled each time through the outer loop.
So is solution ONE necessarily preferred to TWO?
Curiously,
Michael
/* workable solution ONE */
%macro big;
%do outer=1 %to 10;
%macro loop(start=,end=);
%do i = &start %to &end;
/* large section of code */
%put &i;
%end;
%mend loop;
%loop(start=7,end=12);
%loop(start=1,end=6);
%end;
%mend;
%big
/* workable solution TWO */
%macro parse;
%let _jlist = 7 8 9 10 11 12 1 2 3 4 5 6;
%do _j = 1 %to 12;
%let j = %scan(&_jlist,&_j,%str( ));
%put &j;
%end;
%mend;
%parse
>>> Michael Murff <mjm33@msm1.byu.edu> 01/03/05 10:16 AM >>>
Hi SAS gurus,
I frequently have cause to structure do loop indexes as shown in the
functional datastep code example below. To my chagrin these DO
constructs do not seem to be valid in macro syntax. Could someone advise
me on a workaround? I need to nest a large section of code in a macro DO
loop and would rather not have to create two copies of the code with the
only difference being the index sequence.
Many thanks,
Michael Murff
Provo, UT
/*Very useful datastep DO constructs */
*********************************************************;
data _null_;
/* a useful D0 construct */
do i=7 to 12, 1 to 6;
put i;
end;
/* another useful D0 construct */
do j=7,8,9,10,11,12,1,2,3,4,5,6;
put j;
end;
run;
*********************************************************;
/* Apparently invalid macro syntax */
*********************************************************;
%macro testdo1;
/* apparently not available in macro syntax */
%do i=7 %to 12, 1 %to 6;
%put &i;
%end;
%mend;
%testdo1
%macro testdo2;
/* apparently not available in macro syntax */
%do j=7,8,9,10,11,12,1,2,3,4,5,6;
%put &j;
%end;
%mend;
%testdo2
*********************************************************;
|