Tuesday, December 15, 2009

Automatic index variable _i_ in DO OVER

Recently SAS-L started an new topic "Do over can't be nested?".
I think it is very helpful for anyone who is interested with DO OVER.

quote:
Paul Choate says:
A little history lesson - in the 5.18 manual page 44 chapter 4 it says: "You can process more than one array in a DO OVER group if the arrays have the same number of elements and the same index variable."

It later says: "... (DO OVER) arrays use the automatic index variable _I_."
unquote


* Sample code;
data _null_;
array arra a1-a10 (0 1 2 3 4 5 6 7 8 9);
array arrb b1-b10 (10 11 12 13 14 15 16 17 18 19);

_i_=3;
put _i_= arra= arrb=;

_i_=6;
put _i_= arra= arrb=;

do over arra;
put "Start: " _i_=; * _i_ will be initialized to 1;
do over arrb;
put _i_= arra= arrb=;
end;
put "End: " _i_=; * ;
end;
run;

No comments: