VALUE Function

VALUE (name) ;

The VALUE function assigns values by indirect reference. The function takes the name of a matrix and returns the value of that matrix. The VALUE function is useful for retrieving values from a matrix whose name is not known until run time.

The C programming language has the concept of a pointer, which enables you to assign values to preallocated memory. The VALUE function is similar. The name argument contains the name of the matrix from which the value is to be retrieved.

For example, the following statements return the values that are contained in the variable A:

a = {1 2 3};
b = "A";      /* points to A */
c = value(b); /* returns the value of A */
print c;

Figure 23.365: Value of an Indirect Reference

c
1 2 3


You can use the VALUE function in a loop to extract the values of several matrices that have different sizes and shapes, as shown in the following example:

x = {1 2 3};
y = {9 6 10 5};
z = {5 5, 10 0};
name = {"x" "y" "z"};
sums = j(1, ncol(name)); /* allocate space for result */
do i = 1 to ncol(name);
   sums[i] = sum( value(name[i]) ); /* sum(x), sum(y), and sum(z) */
end;
print sums;

Figure 23.366: Sums of Matrices

sums
6 30 20


See also the VALSET subroutine, which performs indirect assignment of matrices.