BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
arbongard
Calcite | Level 5

How would I write a subrountine that takes 2 parameters (a constant and a square matrix). Then adds that constant to the every element of the diagonal of the matrix, and passes the results back in a new parameter?

Then out puts the new matrix after the subtracted constant

I have the general idea but getting stuck on the diagonal part.

1 ACCEPTED SOLUTION

Accepted Solutions
Hutch_sas
SAS Employee

A quick way to add a constant to the diagonal elements of a matrix:

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

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

View solution in original post

1 REPLY 1
Hutch_sas
SAS Employee

A quick way to add a constant to the diagonal elements of a matrix:

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

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

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