A Primer on Using PROC IML



Similar documents
SAS/IML - Interactive Matrix Language

Introduction to Matrix Algebra

Linear Algebra and TI 89

Here are some examples of combining elements and the operations used:

Multiple regression - Matrices

STATISTICS AND DATA ANALYSIS IN GEOLOGY, 3rd ed. Clarificationof zonationprocedure described onpp

Matrix Algebra in R A Minimal Introduction

Lecture 5: Singular Value Decomposition SVD (1)

PTC Mathcad Prime 3.0 Keyboard Shortcuts

1 Introduction to Matrices

A Brief Introduction to SPSS Factor Analysis

Typical Linear Equation Set and Corresponding Matrices

Introduction to Matlab

u = [ 2 4 5] has one row with three components (a 3 v = [2 4 5] has three rows separated by semicolons (a 3 w = 2:5 generates the row vector w = [ 2 3

6. Cholesky factorization

Eigenvalues, Eigenvectors, Matrix Factoring, and Principal Components

MATRIX ALGEBRA AND SYSTEMS OF EQUATIONS. + + x 2. x n. a 11 a 12 a 1n b 1 a 21 a 22 a 2n b 2 a 31 a 32 a 3n b 3. a m1 a m2 a mn b m

Torgerson s Classical MDS derivation: 1: Determining Coordinates from Euclidean Distances

CHAPTER 8 FACTOR EXTRACTION BY MATRIX FACTORING TECHNIQUES. From Exploratory Factor Analysis Ledyard R Tucker and Robert C.

Basic Use of the TI-84 Plus

Basics of STATA. 1 Data les. 2 Loading data into STATA

Financial Econometrics MFE MATLAB Introduction. Kevin Sheppard University of Oxford

Orthogonal Diagonalization of Symmetric Matrices

Linear Algebra Review. Vectors

AMATH 352 Lecture 3 MATLAB Tutorial Starting MATLAB Entering Variables

MATRIX ALGEBRA AND SYSTEMS OF EQUATIONS

R Language Fundamentals

Similar matrices and Jordan form

F Matrix Calculus F 1

Engineering Problem Solving and Excel. EGN 1006 Introduction to Engineering

MATLAB Workshop 3 - Vectors in MATLAB

3.2 Matrix Multiplication

Notes on Applied Linear Regression

Lecture 2 Matrix Operations

Quick Tour of Mathcad and Examples

Chapter 5 Programming Statements. Chapter Table of Contents

a(1) = first.entry of a

CD-ROM Appendix E: Matlab

Creating QBE Queries in Microsoft SQL Server

Elementary Matrices and The LU Factorization

Excel supplement: Chapter 7 Matrix and vector algebra

CS3220 Lecture Notes: QR factorization and orthogonal transformations

(!' ) "' # "*# "!(!' +,

Linear Algebra Notes for Marsden and Tromba Vector Calculus

Solving Mass Balances using Matrix Algebra

EXCEL SOLVER TUTORIAL

December 4, 2013 MATH 171 BASIC LINEAR ALGEBRA B. KITCHENS

MATH10212 Linear Algebra. Systems of Linear Equations. Definition. An n-dimensional vector is a row or a column of n numbers (or letters): a 1.

Using Microsoft Excel Built-in Functions and Matrix Operations. EGN 1006 Introduction to the Engineering Profession

Labels, Labels, and More Labels Stephanie R. Thompson, Rochester Institute of Technology, Rochester, NY

Similarity and Diagonalization. Similar Matrices

ESPResSo Summer School 2012

SAS Tips and Tricks. Disclaimer: I am not an expert in SAS. These are just a few tricks I have picked up along the way.

Beginner s Matlab Tutorial

Math 312 Homework 1 Solutions

Using row reduction to calculate the inverse and the determinant of a square matrix

Math 1050 Khan Academy Extra Credit Algebra Assignment

Statistical Functions in Excel

K80TTQ1EP-??,VO.L,XU0H5BY,_71ZVPKOE678_X,N2Y-8HI4VS,,6Z28DDW5N7ADY013

B) Mean Function: This function returns the arithmetic mean (average) and ignores the missing value. E.G: Var=MEAN (var1, var2, var3 varn);

13 MATH FACTS a = The elements of a vector have a graphical interpretation, which is particularly easy to see in two or three dimensions.

MATLAB Basics MATLAB numbers and numeric formats

Factor Analysis. Chapter 420. Introduction

v w is orthogonal to both v and w. the three vectors v, w and v w form a right-handed set of vectors.

Factor Analysis Example: SAS program (in blue) and output (in black) interleaved with comments (in red)

MS-EXCEL: ANALYSIS OF EXPERIMENTAL DATA

Section 5.3. Section 5.3. u m ] l jj. = l jj u j + + l mj u m. v j = [ u 1 u j. l mj

MATHEMATICS FOR ENGINEERS BASIC MATRIX THEORY TUTORIAL 2

Linear Algebra: Vectors

Data Mining: Algorithms and Applications Matrix Math Review

The Center for Teaching, Learning, & Technology

LESSON QUESTIONS: Bar charts

Method To Solve Linear, Polynomial, or Absolute Value Inequalities:

ing Automated Notification of Errors in a Batch SAS Program Julie Kilburn, City of Hope, Duarte, CA Rebecca Ottesen, City of Hope, Duarte, CA

is in plane V. However, it may be more convenient to introduce a plane coordinate system in V.

Data Tool Platform SQL Development Tools

A workflow triggers that generates a hyperlink (See the route) in the list item in a column called Map.

Vectors 2. The METRIC Project, Imperial College. Imperial College of Science Technology and Medicine, 1996.

Principle Component Analysis and Partial Least Squares: Two Dimension Reduction Techniques for Regression

Solution to Homework 2

Review Jeopardy. Blue vs. Orange. Review Jeopardy

LS.6 Solution Matrices

Operation Count; Numerical Linear Algebra

DETERMINANTS TERRY A. LORING

Using Casio Graphics Calculators

Nonlinear Iterative Partial Least Squares Method

A Short Guide to R with RStudio

EXST SAS Lab Lab #4: Data input and dataset modifications

( ) which must be a vector

STAT10020: Exploratory Data Analysis

Question 2: How do you solve a matrix equation using the matrix inverse?

[1] Diagonal factorization

From The Little SAS Book, Fifth Edition. Full book available for purchase here.

MatLab Basics. Now, press return to see what Matlab has stored as your variable x. You should see:

Miami University RedHawk Cluster Working with batch jobs on the Cluster

Writing Packages: A New Way to Distribute and Use SAS/IML Programs

Chapter 4. Spreadsheets

Abstract: We describe the beautiful LU factorization of a square matrix (or how to write Gaussian elimination in terms of matrix multiplication).

Using SPSS, Chapter 2: Descriptive Statistics

(1) These are incomplete block designs (sometimes balanced) that are resolvable.

Transcription:

Primer on Using PROC IML SS Interactive Matrix Language (IML) is a SS procedure. IML is a matrix language and has built-in operators and functions for most standard matrix operations. To invoke the procedure, start with the PROC IML statement and end with. Reading in Data matrix can be defined in two ways in IML: () manually enter them using code, and (2) define a file containing the matrix which is later invoked in IML. Entering Data in a Matrix: *invokes IML; a = 2; *scalar; b = { 2 3 4}; * x 4 row vector; c = {.0 0 0, 0.2.0 0, 0.8 0.4.0}; *3 x 3 (correlation) matrix; *closes IML; The braces {} encloses the values into a matrix and commas are used to separate rows. Providing a file of elements: ssume that you have a space delimited file containing elements of a 9 x 9 (correlation) matrix called holzinger.txt. The following code is used to read in the file and determine a matrix with the elements from the file matrix.txt. filename matrix 'C:\... '; *directory where file is located; data example; *creating a dataset called 'example'; infile matrix(holzinger.txt); *linking the file holzinger.txt ; *to the filename matrix; input x x2 x3 x4 x5 x6 x7 x8 x9; *arbitrary column labels; run; use example; read all var {x x2 x3 x4 x5 x6 x7 x8 x9} into X; *use all 9 columns of data for matrix X; Printing out matrices of interest IML can either be used interactively where statements are executed immediately or noninteractively. For interactive use, it is convenient to use the reset log print; statement which causes IML to display results in the log file, together with input statements. The print option causes IML to display the result of each assignment statement in the output. Jolynn Pek, ll rights 2008

For example, we want to specify a correlation matrix have SS print out the elements of..0 0.5.0 0.6 0.7.0 and wanted to 0.2 0. 0.8.0 Using reset log print; *invokes IML; reset log print; *displays results in the log file; = {.0 0 0 0, 0.5.0 0 0, 0.6 0.7.0 0, 0.2 0. 0.8.0}; *manually entering the matrix; *closes IML; The log file will display this: NOTE: IML Ready reset log print; = {.0 0 0 0, 0.5.0 0 0, 0.6 0.7.0 0, 0.2 0. 0.8.0}; Using print; *invokes IML; = {.0 0 0 0, 0.5.0 0 0, 0.6 0.7.0 0, 0.2 0. 0.8.0}; *manually entering the matrix; print ; *displays matrix in the output; *closes IML; The output will display this: 0 0 0 0.5 0 0 0.6 0.7 0 0.2 0. 0.8 Note that since IML can be used interactively, matrix was printed in the output without executing the statement. Jolynn Pek, ll rights 2008 2

Functions which create matrices a. I(size) Identity matrix where size = number of diagonal s. b. j(nrow,ncol,x) Constant matrix where nrow = number of rows, ncol = number of columns and x = element. c. diag(vector) Creates a square matrix with the elements of the vector along the main diagonal. d. diag(matrix) Creates a square matrix which retains the main diagonal of the argument matrix. Example code: a = I(6); * 6x6 identity matrix; b = j(5,5,0); *5x5 matrix of 0's; c = j(6,); *6x column vector of 's; d=diag({ }); e=diag({ 2, 3 4}); print a; print b; print c; print d; print e; Note, in using the diag() function, the vector or matrix has to be specified in braces {} and not in brackets (). Output: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 B C D 0 0 0 2 0 0 0 4 Matrix Operations E 0 0 4 Jolynn Pek, ll rights 2008 3

Matrix Operations a. ddition operator: + b. Subtraction operator: c. Sign reverse operator: d. bsolute function: abs(matrix) e. Matrix product operator: * f. Square root function: sqrt(matrix) g. Transpose operator: t(matrix) or ` (backquote character) h. Determinant: det(matrix) i. Matrix inverse operator: inv(matrix) j. Trace of a matrix: tr(matrix) k. Eigen values: eigval(matrix) l. Eigen vectors: eigvec(matrix) m. Minimum value: min(matrix) n. Maximum value: max(matrix) Example code: X ={ 2, 3 4}; Y ={-4 3,-2 -}; a = X+X; *addition; b = X-X; *subtraction; c = -Y; *sign reversal; d = abs(y); *takiing absolute value; e = X*X; *matrix multiplication; f = sqrt(x); *taking square roots of the elements; g = X`; *transpose using back quote; g2 = t(x); *transpose using function; h = det(x); *matrix determinant; i = inv(x); *matrix inverse; j = tr(x); *trace of a matrix; k = eigval(x); *eigen values of matrix; l = eigvec(x); *eigen vector of matrix; m = min(x); *smallest matrix element; n = max(x); *largest matrix element; print a; print b; print c; print d; print e; print f; print g; print g2; print h; print i; print j; print k; print l; print m; print n; Jolynn Pek, ll rights 2008 4

Output: 6 8 G 3 B 0 0 0 0 G2 3 C H 4-3 2-2 D 4 3 2 E 7 0 5 22 F.44236.7320508 2 I -2.5-0.5 K 5.372283 0-0.37228 0 L 0.459736-0.824565 0.9093767 0.5657675 M N 4 Jolynn Pek, ll rights 2008 5