BookmarkSubscribeRSS Feed
akpattnaik
Obsidian | Level 7

Hi Guys,

 

I have two tables as shown in the attachment. I want to create the result table, which is shown at the bottom of the attachment:

  • For the diagonal columns in table 1, i want to populate the values from table 2 
  • Challenge is in table 2 i got a product name column which got a value "A" as i appended it to a table. 

Can someone give me a hand please? I really appreciate everyone who have been helping me so far.

4 REPLIES 4
IanWakeling
Barite | Level 11

Is the DIAG function what you are looking for?   It will convert any vector into a diagonal matrix.  For example

 

proc iml;
   a = diag({1 2 3});
   print a;
quit;
akpattnaik
Obsidian | Level 7

Thanks for your reply. But i believe its something more to that. Can you please have a look at the data which is attached?

i want the values from a different table to be replaced with the diagonals. Appreciate your input and time.  

IanWakeling
Barite | Level 11

I am not understanding what you want,  so can you explain in more detail please?   How do you want to make Table 2 from Table 1?   The step after that is just the DIAG function, as the 2nd "22" in the result matrix is a typo,  right?

akpattnaik
Obsidian | Level 7

Ah, Sorry Ian. My bad. You are right.

I guess i'm not able to think straight now 🙂

Diag is the option.  i was wandering how to put that in the shape of table 1. 

 

proc iml;

N=nrow(table1);

test= diag(table2);

result=??

run;

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