BookmarkSubscribeRSS Feed
e3flator
Calcite | Level 5

I would like to know if in proc iml there is a command similar to the “By” command of many SAS procedures. I have to create a matrix product t(x)*A*x  using the same matrix A but different x vectors.

All x vectors are stored in the same dataset (INPUT) which has a varaible used to filter the different vectors.

  1. E.g.

BY_VARIABLE

X

AT

X1

AT

X2

DE

X1

DE

X2

FR

X1

….

 

Currently I make a cycle on the different values of BY_VARIABLE, filter the dataset based on that value, make the proc iml and store the output in a dataset. I would like to know if it’s possible to use the entire INPUT dataset in the proc iml, specify which is the BY variable and output a dataset with the BY_VARIABLE and the results of the matrix product for each value. 

Thanks in advance

Federica

1 REPLY 1
Rick_SAS
SAS Super FREQ

There is not a BY statement because the SAS/IML statement operates on matrices, not just vectors.  (It also has a DO loop and other features for processing multiple groups.)

For your example, let Y be the matrix whose i_th column is the vector for the i_th value of the BY variable.  Then

M = t(Y)*A*Y

computes all products that appear in the output data set.  There is no need to filer the data prior to calling PROC IML, nor to create/append multiple data sets.  One IML operation is all it takes.

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
  • 1 reply
  • 834 views
  • 0 likes
  • 2 in conversation