Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 02-21-2017 03:35 AM
(1637 views)

I am using IML/SAS in SAS Enterprise Guide for the first time, and want to do the following:

1. Read some datasets into IML matrices

2. Average the matrices

3. Turn the resulting IML matrix back into a SAS data set

My input data sets look something like the following (this is dummy data - the actual sets are larger). The format of the input data sets is also the format I want from the output data sets.

data_set0: d_1 d_2 d_3 1 2 3 4 5 6 7 8 9

I proceed as follows:

proc iml; /* set the names of the migration matrix columns */ varNames = {"d_1","d_2","d_3"}; /* 1. transform input data set into matrix USE data_set_0; READ all var _ALL_ into data_set0_matrix[colname=varNames]; CLOSE data_set_0; USE data_set_1; READ all var _ALL_ into data_set1_matrix[colname=varNames]; CLOSE data_set_1; USE data_set_2; READ all var _ALL_ into data_set2_matrix[colname=varNames]; CLOSE data_set_2; USE data_set_3; READ all var _ALL_ into data_set3_matrix[colname=varNames]; CLOSE data_set_3; /* 2. find the average matrix */ matrix_sum = (data_set0_matrix + data_set1_matrix + data_set2_matrix + data_set3_matrix)/4; /* 3. turn the resulting IML matrix back into a SAS data set */ create output_data from matrix_sum[colname=varNames]; append from matrix_sum; close output_data; quit;

I've been trying loads of stuff, but nothing seems to work for me. The error I currently get reads:

ERROR: Matrix matrix_sum has not been set to a value

What am I doing wrong? Thanks up front for the help.

- Tags:
- iml

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

2 REPLIES 2

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

```
data data_set0;
input d_1 d_2 d_3;
datalines;
1 2 3
4 5 6
7 8 9
;
data data_set1;
input d_1 d_2 d_3;
datalines;
1 2 3
4 5 6
7 8 9
;
data data_set2;
input d_1 d_2 d_3;
datalines;
1 2 3
4 5 6
7 8 9
;
data data_set3;
input d_1 d_2 d_3;
datalines;
1 2 3
4 5 6
7 8 9
;
proc iml;
/* set the names of the migration matrix columns */
varNames = {"d_1","d_2","d_3"};
/* 1. transform input data set into matrix */
USE data_set0;
READ all var _ALL_ into data_set0_matrix[colname=varNames];
CLOSE data_set_0;
USE data_set1;
READ all var _ALL_ into data_set1_matrix[colname=varNames];
CLOSE data_set_1;
USE data_set2;
READ all var _ALL_ into data_set2_matrix[colname=varNames];
CLOSE data_set_2;
USE data_set3;
READ all var _ALL_ into data_set3_matrix[colname=varNames];
CLOSE data_set_3;
/* 2. find the average matrix */
matrix_sum = (data_set0_matrix + data_set1_matrix +
data_set2_matrix + data_set3_matrix)/4;
/* 3. turn the resulting IML matrix back into a SAS data set */
create output_data from matrix_sum[colname=varNames];
append from matrix_sum;
close output_data;
quit;
```

Just minor corrections will make your code work as above 🙂

EDIT: I see you made it work already. Thumbs up 🙂

Are you ready for the spotlight? We're accepting content ideas for **SAS Innovate 2025** to be held May 6-9 in Orlando, FL. The call is **open **until September 16. Read more here about **why** you should contribute and **what is in it** for you!

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.