/*----A FEW IML COMMANDS-------* reset spaces=5 fuzz=.000001; <-- space between matrices, round to 0 ; * multiply ` transpose (BACK quote) <--- X`*X X = {1 2, 3 4}; <-- create matrix, first row 1 2, second is 3 4 A[2,3] <-- subscripts A[2,3] = 4 replaces, ELT = A[2,3] gives element A[1:3,1:3] <--- upper left 3x3 submatrix A[5, ] A[1:3, ] <-- 5th row and 3xn submatrix A[ ,2] <-- column 2 _ _ || <-- join horizontally |_|_| _ // <--------- join vertically |_| C=A//B; D=A||B; |_| FUNCTIONS NROW(A) number of rows in A N=NROW(A); NCOL(A) VECDIAG(A) vector equals diagonal of A V=VECDIAG(X) is {1 4} for our X above L=DIAG(V) <-- makes diagonal matrix with V elts on diagonal 1 0 0 4 L=DIAG(X) <-- replaces off diagonals with 0 (X square) B=INV(X) <--- B is inverse of X G=GINV(A) <-- a generalized inverse D=DET(A) <--- determinant T = TRACE(A) <--- trace = sum of diagonal SUBROUTINE CALL SVD(U,L,Z,X) <-- given X, find U L Z so that X = ULZ', Z'Z=I, U'U=I */ PROC IML; reset spaces=5 fuzz=.0001; A = {1 3, 2 4, 3 3, 5 2}; B = A*{4,-2}; C = A||B; print A[format=2.0] B C[format=2.0]; G = GINV(C); CGC = C*G*C; rank = TRACE(G*C); text= {"Rank can","be computed", "from","generalized","inverse"}; print text G[format=5.2] CGC[format=2.0] rank; %let dsn=A; proc iml; reset fw=4 spaces=5; D = {1.008 2 3, 4 5 6, 7 8 9}; start data_a(D); L=diag(D); names = {X1, x2, X3}; mixedcase = {"X1","x2","X3"}; print D L names mixedcase; create &dsn from L[colname=names]; append from L; finish data_a; G={10.08 8 9, 10 11 12, 13 14 15}; call data_a(G); %let dsn=b; call data_a(D) ; ** store module=data_a; proc print data=a; title "A"; proc print data=b; title "B"; proc iml; C={9 8 7, 6 5 4, 3 2 1}; ** load module=data_a; call data_a(C); proc print data=b; title "new B"; ** check the log !!! ***; run; data study; input subject wt ht age char $; cards; 1 150 70 33 John 2 160 72 50 Bill 3 180 68 21 Dave 4 106 62 38 Mary ; proc iml; names = {subject age wt ht}; use study; read all var names into dat; read point {2 4} var {wt age} into small ; read all var names into fancy [colname = names rowname=char]; print dat small fancy; reset noname; print ,,, "Reset to noname option" ,; ** comma -> skip line, slash-> new page **; print dat small ,, fancy; quit;