proc iml; reset autoname; /* Causes output to display row # and col # */ /* Construct a vector */ /* Create a 1 x 5 vector; columns are separated by a space */ v = {1 2 3 4 5} ; print v; /* Create a 2x2 matrix */ m = {1 2,3 4}; print m; /* Change a value in vector/matrix; change the value 3 to 6 */ v[1,3] = 6; print v; /* Change the value 3 to 6 in matrix m */ m[2,1] = 6; print m; /* Special matrices */ I = { 1 0 0 , 0 1 0 , 0 0 1}; print I; /* Identity matrix of dimensions 3x3 */ I3 = i(3); print i3; /* Vector of ones */ /* j(# rows, # cols, value) */ iota = j(5,1,1); print iota; /* Create an empty 4 x 4 matrix, that will later store output */ empty = j(4,4,.); print empty; /* Loops */ do i=1 to 4; do j=1 to 4; empty[i,j] = i+j; end; end; print empty; /* Matrix operations */ /* Transposes and inverses */ vt = t(v); vt = v` ; print vt; minv = inv(m); print minv; /* Multiplications */ /* Elementwise */ vv = v # v; print vv; /* Matrix multiplication */ mm = m * minv; print mm; /* Importing SAS datasets into IML **Note: data set has to be imported into SAS first */ /* Uses the bweight dataset, reads all obs and columns into matrix named "bw" */ use sashelp.bweight; read all into bw; print bw; read point(1:100) var {weight black married} into bw1; print bw1;