BookmarkSubscribeRSS Feed
coug914
Calcite | Level 5

I'm trying to pull the lower half of a matrix in proc iml. It seems like the VECH function would work perfectly, but I'm running SAS 9.2 and VECH appears to be limited to 9.3. Any suggestions for alternatives? It's all inside a loop and the matrix size changes (with each loop), but these are fairly large matrices (e.g., 3000 X 3000). Thanks!

4 REPLIES 4
IanWakeling
Barite | Level 11

This can be recreated using a short function module,  but it is complicated slightly by the fact that the LOC function operates in row major order while the VECH function operates in column major order, and so the need to transpose the matrix.  The code below should do the trick, but I have no idea how efficient or inefficient this might be with your large matrices.

proc iml;

  start vechalf(x);
    a=nrow(x);
    b=a#a-1;
    return(t(x)[loc(mod(0:b,a)>=int((0:b)/a))]);
  finish;

  x=shape(10:25,4,4);
  print x;
  y=vechalf(x);
  print y;

quit;

coug914
Calcite | Level 5

Actually it appears the symsqr function did what i needed.

thanks,

Rick

IanWakeling
Barite | Level 11

Thanks for the info, I had read this article and come to the conclusion that VECH was something completely new, but it appears that SYMSQR does the same thing, only it reads the lower diagonal elements in row-major order, so the two do give different results.  It would be nice if  the 9.3 documentation for VECH could  be changed to include a link to SYMSQR (and vice versa).

Ian.

Rick_SAS
SAS Super FREQ

Thanks for the suggestion. The 9.3 documentation can't be changed, but the next release of the documentation will include links between SYMSQR <--> VECH and between SQRSYM <--> SQRVECH.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 4 replies
  • 1131 views
  • 3 likes
  • 3 in conversation