options ls=80 ; /* example of Gram-Schmidt orthognormalization */ /* ...the easy way -- let SAS do the hard work */ /* */ data a ; input x1 x2 x3 x4 x5 ; u1 = x1 ; * copy to start ; cards ; 1 1 0 2 -1 1 -1 1 1 1 0 0 1 -1 1 1 1 1 1 0 1 1 0 2 0 ; /* Gram-Schmidt the lazy way */ /* just regressions of new vector on old */ proc reg data=a ; x2: model x2 = u1 / noint ; output out=o2 r=u2 ; run ; proc reg data=o2 ; x3: model x3 = u1 u2 / noint ; output out=o3 r=u3 ; run ; proc reg data=o3 ; x4: model x4 = u1 u2 u3 / noint ; * output out=o4 r=u4 ; * zero residuals ; run ; proc reg data=o3 ; * still just 3 U's ; x5: model x5 = u1 u2 u3 / noint ; output out=o4 r=u4 ; run ; data all ; set o4 ; * use x's and 4 u's ; /* check X = U*S by recreating X */ newx2 = (1/2)*u1 + u2 ; newx3 = (1/2)*u1 + (-1/3)*u2 + u3 ; newx4 = (3/2)*u1 + (1/3)*u2 + (-1)*u3 ; newx5 = (0)*u1 + (-2/3)*u2 + (4/5)*u3 + u4 ; run ; proc print data=all ; var x1-x5 u1-u4 newx2-newx5 ; title 'U = unnormalized columns of Q' ; run ;