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 10-09-2015 06:53 AM
(847 views)

I have a matrix, *x*, that is numeric and 49X47. The second row contains all missing values. I would like to reshape it to a square matrix that is 47x47 by eliminating the first and second rows.

The SHAPE function isn't working:

** x2=shape(x,3:49,47);**

I'm getting execution errors telling me that the "*argument should be a scalar.*"

How do I resolve this?

Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions

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

The documentation for the SHAPE function specifies that the second argument should be the number of columns in the result matrix. You are sending in a vector, which is why you are getting an error.

First use the subscript operator to extract the nonmissing rows, then reshape:

`x2 = shape( x[3:49, ], 47 );`

4 REPLIES 4

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

The documentation for the SHAPE function specifies that the second argument should be the number of columns in the result matrix. You are sending in a vector, which is why you are getting an error.

First use the subscript operator to extract the nonmissing rows, then reshape:

`x2 = shape( x[3:49, ], 47 );`

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

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

That specification of the *Shape* function worked. When I print the resulting matrix within IML, it is square. However, when I create output containing that matrix, the output resolves to a vector:

Vec2 = the resulting square matrix

create Outputx var {Vec2};

append;

close Outputx;

run;*end Proc IML;

Outputx contains a single column with nxn rows.

Why does Outputx not contain the square matrix Vec2?

Thank you.

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

Why does Outputx not contain the square matrix Vec2?

Because you are using the VAR clause in the CREATE statement. Use the FROM clause to write a matrix, as discussed in the article "Writing data from a matrix to a SAS data set."

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.