Hey @SASKiwi
On of my personal favourite use case is expanding string into an array:
data _null_;
string = "A1B2C3";
array a[6] $ 1;
call POKELONG(string, ADDRLONG(a[1]));
put _all_;
run;
The other one I've been using was when I was showing to my students that you can declare an array pointing multiple times to the same variables. I was showing that subsequent array elements pointing the same addresses:
data _null_;
x=1; y=2;
array a[*] x y x y;
do i=1 to dim(a);
addr = addrlong(a[i]);
put addr= hex16.;
end;
run;
Third one was for reversing order of rows in a 2-dimensional array:
%macro prt(a);
n=dim1(&a.)*8;
do i=1 to dim1(&a.);
call POKELONG(PEEKCLONG(ADDRLONG(&a.[i,1]),n)
,ADDRLONG(print[1])
);
put (print:) (+1 z3.0-R); drop print:;
end;
put;
%mend prt;
%macro swapRows(a,i,j);
n=dim1(&a.)*8; drop i j n;
i=&i.; j=&j.;
call POKELONG(PEEKCLONG(ADDRLONG(&a.[i,1]),n)
,ADDRLONG(tmp[1]));
call POKELONG(PEEKCLONG(ADDRLONG(&a.[j,1]),n)
,ADDRLONG(&a.[i,1]));
call POKELONG(PEEKCLONG(ADDRLONG(tmp[1]),n)
,ADDRLONG(&a.[j,1]));
%mend swapRows;
options ls=max ps=max;
data _null_;
array a[20,20] (1:400);
array tmp[20] _temporary_;
array print[20];
%prt(a);
%swapRows(a,1,20) /* swap row 1 and 20, etc. */
%swapRows(a,2,19)
%swapRows(a,3,18)
%swapRows(a,4,17)
%swapRows(a,5,16)
%swapRows(a,6,15)
%swapRows(a,7,14)
%swapRows(a,8,13)
%swapRows(a,9,12)
%swapRows(a,10,11)
%prt(a);
run;
BTW. printing 2-dim array to the also is easier(only 1 loop) and faster.
Bart
... View more