Chapter Contents
Chapter Contents
Previous
Previous
Next
Next
Working with Matrices

Matrices with Multiple Elements

To enter a matrix having multiple elements, use braces ({ }) to enclose the data values and, if needed, commas to separate rows. Inside of the braces, all elements must be either numeric or character. You cannot have a mixture of data types within a matrix. Each row must have the same number of elements.

For example, suppose that you have one week of data on daily coffee consumption (cups per day) for your office of four people. Create a matrix COFFEE with each person's consumption as a row of the matrix and each day represented by a column. First, submit the so that results are displayed as you submit statements.

   >  reset print;
   >  coffee={4 2 2 3 2,
   >          3 3 1 2 1,
   >          2 1 0 2 1,
   >          5 4 4 3 4};

           COFFEE        4 rows      5 cols    (numeric)

                   4         2         2         3         2
                   3         3         1         2         1
                   2         1         0         2         1
                   5         4         4         3         4
Now create a character matrix called NAMES with rows containing the names of the people in your office. Note that when you do not use quotes, characters are converted to uppercase.
   >  names={Jenny, Linda, Jim, Samuel};

           NAMES         4 rows      1 col     (character, size 6)

                                 JENNY
                                 LINDA
                                 JIM
                                 SAMUEL
Notice that the output with the RESET PRINT statement includes the dimension, type, and (when type is character) the element size of the matrix. The element size represents the length of each string, and it is determined from the length of the longest string.

Now, display the COFFEE matrix using NAMES as row labels by specifying the ROWNAME= option in the PRINT statement.

   >  print coffee [rowname=names];

         COFFEE
         JENNY          4         2         2         3         2
         LINDA          3         3         1         2         1
         JIM            2         1         0         2         1
         SAMUEL         5         4         4         3         4

Chapter Contents
Chapter Contents
Previous
Previous
Next
Next
Top
Top

Copyright © 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.