SAS/IML

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/IMLEdit

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 statistique*/
	print student ;  
quit;
 
proc reg data = base ; 
model y = x / I XPX  ; 
run ; quit ;

OptimizationEdit

IML includes lots of optimization routines.


Random Number GenerationEdit

proc iml ;
   seed = 123456; 
   c = j(5,1,seed); 
   b = uniform(c); 
   print b; 
quit ;

RessourcesEdit

Last modified on 17 September 2009, at 08:08