Appendix B

BASIC MATRIX OPERATIONS IN PROC IML

B.1 ASSIGNING SCALARS

Scalars can be viewed as 1 × 1 matrices and can be created using Proc IML by using the statement x=scalar_value or x={scalar_value}. As an example, the statements x=14.5 and x={14.5} are the same and both store the value 14.5 in x. We can also store character values as the commands name=’James’ and hello=’Hello World’ illustrate.

The stored values in the variables can easily be determined by using the print command in Proc IML. For example to view the values in the variables x, name, and hello use the command Print x name hello.

B.2 CREATING MATRICES AND VECTORS

As mentioned in Appendix A, it is easy to create matrices and vectors in Proc IML. The command A={24, 3 1} will create the matrix

images

Each row of the matrix is separated by a comma. That is, each row of the above command yields a row vector. For instance, the command A={1 2 3 4} creates the row vector A = [1 2 3 4].

If we separate each entry in the row vector by a comma, we will get a column vector. As an example, the command A={1,2,3,4} creates the column vector

images

These commands can easily be extended to create matrices consisting of character elements. For example, the command A={’a’ ’b’, ’c’ ’d’} will create the matrix

B.3 ELEMENTARY MATRIX OPERATIONS

B.3.a ...

Get Applied Econometrics Using the SAS® System now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.