CALL STRUCTINDEX Routine

Enables you to access each structure element in an array of structures.
Category: C Helper

Syntax

CALL STRUCTINDEX(struct_array, index, struct_element);

Required Arguments

struct_array
specifies an array.
index
is a 1–based index as used in most SAS arrays.
struct_element
points to an element in the array.

Example

In the first part of this example, the following structures and function are defined by using PROC PROTO.
proc proto package=sasuser.mylib.str2;
struct point{
   short s;
   int i;
   long l;
   double d;
};

struct point_array {
   int            length;
   struct point p[2];
   char           name[32];
};
run;
In the second part of this example, the PROC FCMP code segment shows how to use the STRUCTINDEX CALL routine to retrieve and set each point structure element of an array called P in the POINT_ARRAY structure:
options pageno=1 nodate ls=80 ps=64;

proc fcmp libname=sasuser.mylib;
   struct point_array pntarray;
   struct point pnt;

   pntarray.length = 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;
Results of Setting the Point Structure Elements of an Array
                                 The SAS System                                1

                               The FCMP Procedure

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}