MATTRIB Statement

MATTRIB name <ROWNAME=row-name> <COLNAME=column-name> <LABEL=label> <FORMAT=format> ;

The MATTRIB subroutine associates printing attributes with matrices.

The input arguments to the MATTRIB subroutine are as follows:

name

is a character matrix or quoted literal that contains the name of a matrix.

row-name

is a character matrix or quoted literal that specifies row names.

column-name

is a character matrix or quoted literal that specifies column names.

label

is a character matrix or quoted literal that associates a label with the matrix. The label argument has a maximum length of 256 characters.

format

is a valid SAS format.

The MATTRIB statement associates printing attributes with matrices. Each matrix can be associated with a ROWNAME= matrix and a COLNAME= matrix, which are used whenever the matrix is printed to label the rows and columns, respectively. The statement is written as the keyword MATTRIB followed by a list of one or more names and attribute associations. It is not necessary to specify all attributes. The attribute associations are applied to the previous name. Thus, the following statement associates a row name RA and a column name CA to a, and a column name CB to b:

a = {1 2 3, 4 5 6};
ra = {"Row 1", "Row 2"};
ca = 'C1':'C3';
b = 1:4;
cb = {"A" "B" "C" "D"};
mattrib a rowname=ra colname=ca  b colname=cb;
print a, b;

Figure 24.206: Matrix Attributes

a
  C1 C2 C3
Row 1 1 2 3
Row 2 4 5 6

b
A B C D
1 2 3 4


You cannot group names. The following statement does not associate anything with a. In fact, it clears any attributes that were previously associated with a.

mattrib a b colname=cb;
print a, b;

Figure 24.207: Modified Matrix Attributes

a
  C1 C2 C3
Row 1 1 2 3
Row 2 4 5 6

b
A B C D
1 2 3 4


The values of the associated matrices are not looked up until they are needed. Thus, they need not have values at the time the MATTRIB statement is specified. They can be specified later when the object matrix is printed. The attributes continue to bind with the matrix until reassigned with another MATTRIB statement. To eliminate an attribute, specify EMPTY as the name (for example, ROWNAME=EMPTY). Use the SHOW NAMES statement to view current matrix attributes.

The following example uses all options in the MATTRIB statement:

rows = "xr1":"xr3";
cols = "cl1":"cl4";
x = {1 1 1 1,
     2 2 2 2,
     3 3 3 3};
mattrib x rowname=rows
          colname=cols
          label={"My Matrix, x"}
          format=5.2;
print x;

Figure 24.208: Matrix Attributes

My Matrix, x
  cl1 cl2 cl3 cl4
xr1 1.00 1.00 1.00 1.00
xr2 2.00 2.00 2.00 2.00
xr3 3.00 3.00 3.00 3.00