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.

142 Data Structures Chapter 7<br />

Matrices<br />

P[1,1]+=1;<br />

Show(P);<br />

P=[3 2 3,<br />

4 5 6,<br />

7 8 9];<br />

Ranges of Rows or Columns<br />

If you are working with a range of subscripts, use the Index() function :: to create matrices of ranges.<br />

T1=1::3; // creates the vector [1 2 3]<br />

T2=4::6; // creates the vector [4 5 6]<br />

T3=7::9; // creates the vector [7 8 9]<br />

T=T1|/T2|/T3; // concatenates the vectors into a single matrix<br />

T[1::3, 2::3]; // refers to rows 1 through 3, columns 2 and 3<br />

[2 3, 5 6, 8 9]<br />

T[index(1,3), index(2,3)]; // equivalent Index function<br />

[2 3, 5 6, 8 9]<br />

Inquiry Functions<br />

The NCol() and NRow() functions return the number of columns and rows in a matrix (or data table),<br />

respectively:<br />

NCol([1 2 3,4 5 6]); // returns 3 (for 3 columns)<br />

NRow([1 2 3,4 5 6]); // returns 2 (for 2 rows)<br />

To determine whether a value is a matrix, use the Is Matrix() function, which returns a 1 if the argument<br />

evaluates to a matrix.<br />

A = [20, 64, 3];<br />

B = {20, 64, 3};<br />

IsMatrix(A); // returns 1 for yes<br />

IsMatrix(B); // returns 0 for no<br />

Comparisons, Range Checks, and Logical Operators<br />

JMP’s comparison, range check, and logical operators work with matrices and produce matrices of<br />

elementwise Boolean results. You can compare conformable matrices.<br />

A=B; // greater or equal<br />

A==B; // equal to<br />

A!=B; // not equal to<br />

A

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

Saved successfully!

Ooh no, something went wrong!