14.03.2014 Views

Scripting Guide - SAS

Scripting Guide - SAS

Scripting Guide - SAS

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 7 Data Structures 153<br />

Matrices<br />

5 3 7 1,<br />

9 9 8 8,<br />

1 5 4 3]);<br />

[1,3,8,3]<br />

Calculate Diagonal Quadratic Forms<br />

The VecQuadratic() function calculates the hats in regression that go into the standard errors of<br />

prediction or the Mahalanobis or T2 statistics for outlier distances. Vec Quadratic(Sym, X) is<br />

equivalent to calculating VecDiag(X*Sym*X`).The first argument is a symmetric matrix, usually an<br />

inverse covariance matrix. The second argument is a rectangular matrix with the same number of columns<br />

as the symmetric matrix argument.<br />

Return the Sum of Diagonal Elements<br />

The Trace() function returns the sum of the diagonal elements for a square matrix.<br />

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

trace(D); // returns 1<br />

Generate a Row Vector of Integers<br />

The Index() function generates a row vector of integers from the first argument to the last argument. A<br />

double colon :: is the equivalent infix operator.<br />

6::10;<br />

[6 7 8 9 10]<br />

Index(1,5);<br />

[1 2 3 4 5]<br />

The optional increment argument changes the default increment of +1.<br />

Index(0.1, 0.4, 0.1);<br />

[0.1, 0.2, 0.3, 0.4]<br />

The increment can also be negative.<br />

Index(6, 0, -2);<br />

[6, 4, 2, 0]<br />

The default value of the increment is 1, or -1 if the first argument is higher than the second.<br />

Reshape a Matrix<br />

The Shape() function reshapes an existing matrix across rows to be the specified dimensions. The<br />

following example changes the 3x4 matrix a into a 12x1 matrix:<br />

a=[1 1 1, 2 2 2, 3 3 3, 4 4 4];<br />

shape(a, 12, 1)<br />

[1,1,1,2,2,2,3,3,3,4,4,4]

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

Saved successfully!

Ooh no, something went wrong!