Presentation is loading. Please wait.

Presentation is loading. Please wait.

SAS Interactive Matrix Language Computing for Research I Spring 2012 Ramesh.

Similar presentations


Presentation on theme: "SAS Interactive Matrix Language Computing for Research I Spring 2012 Ramesh."— Presentation transcript:

1 SAS Interactive Matrix Language Computing for Research I Spring 2012 Ramesh

2 Solve this system of linear equations: 3x + 2y − 4z = 11 5x − 4y = 9 3y + 10z = 42 In matrix form = =

3 Reading in Data proc iml; n = 3; *scalar; b = {11 9 42}; *1 x 3 row vector; A = {3 2 -4, 5 -4 0, 0 3 10}; *3 x 3 matrix; print n b a; quit;

4 Matrix Operators: Arithmetic Addition: + Subtraction: - Division, Elementwise: / Multiplication, Elementwise: # Multiplication, Matrix: * Power, Elementwise: ## Power, Matrix: ** Concatenation, Horizontal: || Concatenation, Vertical: // Number of rows: nrow() Number of columns: ncol()

5 Subscript Operations [ ] Addition + Multiplication # Mean : Sum of squares ## Maximum <> Minimum >< Index of maximum Index of minimum >:< Transpose: ` (Near number 1 on keyboard) Determinant: det(matrix) Inverse: inv(matrix) Trace: tr(matrix) Select a single element: i,j Select a row: i, Select a column:,j

6 Creating special Matrices: Identity matrix with dimension = size : I(size) Matrix having # rows = nrow # cols = ncol with all elements = x : j(nrow,ncol,x) Diagonal matrix: diag(vector) (diag(matrix)) Block diagonal matrix: block (M1, M2,...)

7 proc iml; call randseed(9087235); y = j(400,1); call randgen(y,normal'); z = j(100,1); call randgen(z,'normal', 2, 2.5); x = y // z; create a var{"x"}; append; close a; submit; proc univariate data=a; var x; histogram /kernel; run; endsubmit; Calling SAS PROC’s into IML

8 proc iml; do i=1 to 3; call randseed(9087235); mean=i*2; var=0.5*i; y = j(400,1); call randgen(y, 'normal'); z = j(100,1); call randgen(z, 'normal',mean, var); x = y // z; create a var {"x"}; append; close a; submit; proc univariate data=a noprint; var x; histogram / kernel; run; endsubmit; end; Using DO loops

9 data mult; input v1 v2 v3; datalines; 0.801 121.41 70.42 0.824 127.70 72.47 0.841 129.20 78.20 0.816 131.80 74.89 0.840 135.10 71.21 0.842 131.50 78.39 0.820 126.70 69.02 0.802 115.10 73.10 0.828 130.80 79.28 0.819 124.60 76.48 0.826 118.31 70.25 0.802 114.20 72.88 0.810 120.30 68.23 0.802 115.70 68.12 ; proc iml; use mult; read all into v; X=v`*v; print v; run;


Download ppt "SAS Interactive Matrix Language Computing for Research I Spring 2012 Ramesh."

Similar presentations


Ads by Google