options ps=65;

title 'SAS(IML)example21';

 

/*creating a matrix from a SAS dataset*/

data imldata;

  input x1 x2 x3;

  datalines;

        2 4 8

        3 9 1

        9 4 8

        1 1 1

        2 7 8

        ;

run;

 

proc iml;

   use imldata;

   read all into imlmatrix;

   read all var{x1 x3} into imlmatrix0;

        *imlmnew=t(imlmatrix)*imlmatrix0;

   print imlmatrix imlmatrix0;

   print imlmatrix, imlmatrix0;

quit;

*run;

 

/*creating a SAS matrix and then a dataset from the matrix*/

proc iml;

   imlmatrix1={

        2 4 8,

        3 9 1,

        9 4 8,

        1 1 1,2 7 8}

        ;

   print imlmatrix1;

   create newdata from imlmatrix1;

   append from imlmatrix1;

   close newdata;

   quit;

run;

 

proc print data=newdata;

run;

 

/*matrix operation and eigenvalues and vectors*/

proc iml;

   a={1 3 4,7 1 0};

 

   rown_a=nrow(a);

   coln_a=ncol(a);

   print a, rown_a, coln_a;

  

   ata=a*t(a);

   *rootata=root(ata);

   *rootsq=t(rootata)*rootata;

   print ata; *,rootata,rootsq;

 

   ata_inv=inv(ata);

   test=(ata_inv)*(ata);

   print ata_inv,test;

 

   eval=eigval(ata);

   evec=eigvec(ata);

   print eval, evec;

 

   call eigen(lambda,p,ata);

   print lambda, p;

 

   lam_half=root(diag(lambda));

   ata_half=p*lam_half*t(p);

   testt=p*diag(lambda)*t(p);

   print lam_half, ata_half, testt;

 

   call svd(left,mid,right,ata);

   print left,mid,right;

quit;