BookmarkSubscribeRSS Feed
dvtarasov
Obsidian | Level 7

I have a dataset in which three variables (let's call them X, Y, and Z) are to be written into matrices in PROC IML and have some calculations performed upon them. The result of the calculations I need to export to an Excel file. Another column in the original dataset (let's call it N) will not be used in any calculations, but I need it written to the Excel spreadsheet alongside the output of the calculation.

 

How do I ensure that the values in N line up with the corresponding results in the output? I suspect that a loop of some kind is needed (for every record in N, (write X, Y, and Z to matrices, perform the calculations, write N to Excel, write results to Excel)). Am I right about the loop? Is it possible to have several different steps within one loop? And what is the exact syntax for this?

3 REPLIES 3
PaigeMiller
Diamond | Level 26

If PROC IML is not changing the order of the data, you would write the IML results into a SAS data set, and then merge with the original data set that contains N.

 

If IML is changing the order of the data, you'd need to include N in your IML matrices and sort/re-arrange N the same as you are doing with the rest of the data.

--
Paige Miller
dvtarasov
Obsidian | Level 7

Suppose I now have a matrix with two columns (one read from N, the other from X), and I need to multiply the matrix elementwise by the matrix that was read from Y. What is the syntax for leaving the column in the first matrix that came from N unchanged? 

PaigeMiller
Diamond | Level 26

Assuming matrix X has variable X in column 1 and variable N in column 2

 

newcolumn=x[:,1]#y;

 

But it sounds like there's really no reason to put X and N into the same matrix in IML.

--
Paige Miller

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 1224 views
  • 0 likes
  • 2 in conversation