Using arrays in P-STAT
In a real life problem a large file might contain a variable such
as Name entered in a random order. That variable could then be
selected and rearranged as a vector using a MODIFY command
with the COLLECT function and the SORT option. File "letters"
used in this example is already rearranged as a sorted vector.
File letters (1 row, 16 variables) contains the values:
A B C D E F G H I J K L
It is easy to create a 2 dimensional array with the SPLIT
function. It is not so easy to create an array that is
rotated 90 degrees. For this we use P-STAT's array facility.
SPLIT result Use of an ARRAY
A B C D A E I
E F G H B F J
I J K L C K G
D H L
DEFINE.ARRAY cc:c(3,4) $ An array must be named and
defined before it is used.
PROCESS letters
[ GEN ##next = 1; Scratch variable ##next moves
DO ##j=1,3; through the array one element
DO ##k=1,4; at a time. ##j and ##k control
SET cc(##j,##k) = v(##next); the placement of the cells in
INC ##next; the array named "cc".
ENDDO;
ENDDO;
DO ##k=1,4; A final DO loop is used to PUT
PUT cc(1,##k) cc(2,##k) cc(3,##k); the elements of array cc on the
ENDDO; screen or in a designated print
] $ file.
If you would like to see a macro that allows variable dimensions
in the array, email support@pstat.com with the subject "Array macro".