BookmarkSubscribeRSS Feed
bri11
Calcite | Level 5

what is an example of a subroutine module with 2 parameters, a constant and a square matrix.

that adds the constant value to every element of the diagonal of the matrix, and passes  the result

back in a new parameter? I'm having a hard time understanding this stuff so lots of comments would

be unbelievably helpful.

1 REPLY 1
Hutch_sas
SAS Employee

proc iml;

start AddToDiag( result, A, B);

    /* add B to diagonal of a square matrix A */

    result = A + diag(  j(nrow(A),  1,   B)  );

finish;

/* test it out */

m = {1 1 1,

        2 2 2,

        3 3 3 };

lambda = 3;

run AddToDiag( MPlusLambda, m, lambda);

print M lambda MPlusLambda;

quit;

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
  • 785 views
  • 0 likes
  • 2 in conversation