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 09-24-2016 06:12 AM
(7745 views)

I receive the error: **"(execution) Invalid subscript or subscript out of range**" when try to create a submatrix *tmp* which is based on matrix *FD* which contains all variables and observations from the dataset *WFD* (which contains 62 columns/variables and 2108 rows).

In *tmp*, I want to sum row 1 to 34, and row 35 to 69, and so on, until it reaches row 2074 to 2108 from the *FD* matrix, so that finally, the tmp matrix becomas a 62x62 matrix.

**Do anyone see what I am doing wrong in my code?**

Note: I have tried to find the mistake by looking in the log, i.e. by trying to find this reference point: *operation: [ at line 2965 column 194, *but I really don't understand where in the log I can find this lines and columns with really high numbers.

Help is very appreciated.

**The code:**

data tmpf ; set WFD;

run;

proc iml;

use tmpf(drop = year);

read all var _all_ into FD;

k = 0;

do i = 1 to 2108 by 34;

j = i+33;

k = k+1;

rows = i:j;

cols = k:k;

tmp = fd[rows,cols];

DMD = DMD // tmp ;

end;

**The log:**

NOTE: There were 14756 observations read from the data set WEBWORK.WFD.

NOTE: The data set WEBWORK.TMPF has 2108 observations and 63 variables.

NOTE: DATA statement used (Total process time):

real time 0.13 seconds

cpu time 0.05 seconds

NOTE: IML Ready

ERROR: (execution) Invalid subscript or subscript out of range.

operation : [ at line 2650 column 193

operands : fd, rows, cols

FD 2108 rows 60 cols (numeric)

rows 1 row 34 cols (numeric)

cols 1 row 1 col (numeric)

61

Best regards,

Birgitte

1 ACCEPTED SOLUTION

Accepted Solutions

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

I think the problem is the number of columns in FD. The log says it has 60 columns, however the loop:

do i = 1 to 2108 by 34;

will iterate 62 times. So the error is occuring on the 61st iteration when you try to access the 61st column.

3 REPLIES 3

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

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

I think the problem is the number of columns in FD. The log says it has 60 columns, however the loop:

do i = 1 to 2108 by 34;

will iterate 62 times. So the error is occuring on the 61st iteration when you try to access the 61st column.

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

Thank you!

Indeed, I think that was the problem. I discovered that I made a mistake initially when I made the dataset (WFD) that I use to create the FD matrix, and therefore I had a smaller column range than planned. When I changed it to the correct one the code above worked.

Birgitte

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. **

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.