BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
xtc283x
Quartz | Level 8

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
Rick_SAS
SAS Super FREQ

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 );

View solution in original post

4 REPLIES 4
Rick_SAS
SAS Super FREQ

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 );
IanWakeling
Barite | Level 11

I think the subscript operator alone is suficient here.  The shape function does nothing as the reduced matrix already has 47 rows and 47 columns.

xtc283x
Quartz | Level 8

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.

Rick_SAS
SAS Super FREQ

 

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

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 4 replies
  • 1879 views
  • 2 likes
  • 3 in conversation