411 REFERENCE · Wikibooks
SAS/IML
Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.
IML is an Interactive Matrix Programming Language for SAS. This is similar to R, Matlab and Stata/Mata language. You deal with matrix and you can perform any operation on those matrix.
Least Squares in SAS/IML
data base ;
input x u ;
cards ;
1 -1
2 1
3 -1
4 1
5 -1
;
run ;
proc print data = base ; run ;
data base ;
set base ;
y = 1 + x + u ;
cste = 1 ;
run ;
proc print data = base ; run ;
proc iml;
use base; /*Reads the data*/
read all var {cste x} into x; /*creates matrix*/
read all var {y} into y;
beta=inv(x`*x)*(x`*y); /*computes point estimates*/
print beta;
yhat = x*beta; /*computes predicted values*/
print yhat ;
res = y - yhat ; /*Computes residuals*/
print res ;
SSR = res`*res; /*Computes the sum of squared residuals*/
print SSR ;
hatsigma = SSR / (nrow(y) - ncol(x)); /*Estimates the variance of u*/
print hatsigma ;
sigmabeta = hatsigma * inv(x`*x); /*Computes the variance of the estimator */
print sigmabeta ;
sebeta = sqrt(vecdiag(sigmabeta)); /*Computes standard error for each coefficient*/
print sebeta ;
student = beta / sebeta ; /* Computes the Student t statistic*/
print student ;
quit;
proc reg data = base ;
model y = x / I XPX ;
run ; quit ;
Optimization
IML includes lots of optimization routines.
Random Number Generation
proc iml ;
seed = 123456;
c = j(5,1,seed);
b = uniform(c);
print b;
quit ;
Resources
SAS Help for IML
Introduction to SAS IML (1000 pages, pdf)
Introduction to SAS IML by Michael Friendly