The STRUCTINDEX CALL routine enables you to access each
structure element in an array of structures. When a structure contains
an array of structures, you can access each structure element of the
array by using the STRUCTINDEX CALL routine. The STRUCTINDEX CALL
routine has the following form:
CALL STRUCTINDEX(struct_array, index, struct_element);
Struct_array specifies
an array;
index is a 1–based
index as used in SAS arrays; and
struct_element points
to an element in the arrays.
In the first part of
this example, the following structures and function are defined using
PROC PROTO:
struct point{
short s;
int i;
long l;
double d;
};
struct point_array {
int length;
struct point * p;
char name[32];
};
struct point * struct_array(int);
In the second part of
this example, the PROC FCMP code segment shows how to use the STRUCTUREINDEX
CALL routine to get and set each POINT structure element of an array
called P in the POINT_ARRAY structure:
struct point_array pntarray;
struct point pnt;
/* Call struct_array to allocate an array of 2 POINT structures. */
pntarray.p = struct_array(2);
pntarray.plen = 2;
pntarray.name = "My funny structure";
/* Get each element using the STRUCTINDEX CALL routine and set values. */
do i = 1 to 2;
call structindex(pntarray.p, i, pnt);
put "Before setting the" i "element: " pnt=;
pnt.s = 1;
pnt.i = 2;
pnt.l = 3;
pnt.d = 4.5;
put "After setting the" i "element: " pnt=;
end;
run;
The program writes the
following results to the SAS log.
Output from the STRUCTINDEX CALL Routine
Before setting the 1 element: PNT {s=0, i=0, l=0, d=0}
After setting the 1 element: PNT {s=1, i=2, l=3, d=4.5}
Before setting the 2 element: PNT {s=0, i=0, l=0, d=0}
After setting the 2 element: PNT {s=1, i=2, l=3, d=4.5}