14.03.2014 Views

Scripting Guide - SAS

Scripting Guide - SAS

Scripting Guide - SAS

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 7 Data Structures 143<br />

Matrices<br />

You can use the Any() or All() operators to summarize matrix comparison results. Any() returns a 1 if<br />

any element is nonzero. All() returns a 1 if all elements are nonzero.<br />

[2 2]==[1 2] // returns [0 1], therefore:<br />

All([2 2]==[1 2]) // returns 0<br />

Any([2 2]==[1 2]) // returns 1<br />

Min() or Max() return the minimum or maximum element from the matrix or matrices given as<br />

arguments.<br />

A=[1 2 3, 4 5 6, 7 8 9, 10 11 12];<br />

B=[0 1 2, 2 1 0, 0 1 1, 2 0 0];<br />

Min(A); // returns 1<br />

Max(A); // returns 12<br />

Min(A,B); // returns 0<br />

Numeric Operations<br />

You can perform numeric operations (such as subtraction, addition, and multiplication) on matrices. Most<br />

statistical methods are expressed in compact matrix notation and can be implemented in JSL.<br />

For example, the following expression uses matrix multiplication and inversion to illustrate least squares<br />

regression:<br />

b<br />

Implement this equation through the following JSL expression:<br />

Basic Arithmetic<br />

= ( X′X) – 1 X′y<br />

b = Inv(X`*X)*X`*y;<br />

You can perform the following basic arithmetic on matrices:<br />

• addition<br />

• subtraction<br />

• multiplication<br />

• division (multiplying by the inverse)<br />

Note: The standard multiply operator is a matrix multiplier, not an elementwise multiplier.<br />

To perform matrix multiplication, use one of the following methods:<br />

• * operator<br />

• Multiply() function<br />

• Matrix Mult() function<br />

To perform matrix division, use one of the following methods:<br />

• / operator

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!