SAS Code Help - What am I doing wrong?

Reply
Occasional Learner
Posts: 1

SAS Code Help - What am I doing wrong?

I am just learning SAS.  I am doing a simple problem for a statistics class using SAS 9.4 and have run into a problem that I do not understand the error message and how to resolve the error.  The proble is to create an inverse of a matrix.

 

The following is the code I used:

 

proc iml;

A={1 2, 2 -2, 3 10};

B=A`;

print A B;

run;

AB=A*B;

print AB;

run;

invAB=inv(AB);

print invAB;

run;

 

The following is the error message that I am receiving:

1    proc iml;

NOTE: Writing HTML Body file: sashtml.htm

NOTE: IML Ready

2    A={1 2, 2 -2, 3 10};

3    B=A`;

4    print A B;

5    run;

NOTE: Module MAIN is undefined in IML; cannot be RUN.

6

7    AB=A*B;

8    print AB;

9    run;

NOTE: Module MAIN is undefined in IML; cannot be RUN.

10

11   invAB=inv(AB);

ERROR: (execution) Matrix should be non-singular.

 

 operation : INV at line 11 column 10

 operands  : AB

 

AB      3 rows      3 cols    (numeric)

 

         5        -2        23

        -2         8       -14

        23       -14       109

 

 statement : ASSIGN at line 11 column 1

12   print invAB;

ERROR: Matrix invAB has not been set to a value.

 

 statement : PRINT at line 12 column 1

13   run;

NOTE: Module MAIN is undefined in IML; cannot be RUN.

 

I am using code that was supplied by the instructor (which worked).  I changed nothing with the instructor's code, but can not get a resolution. What am I doing wrong?

 

Thank you for your help

Thank you for your assistance.

Frequent Contributor
Posts: 144

Re: SAS Code Help - What am I doing wrong?

[ Edited ]

If I'm not mistaken, the determinant of the matrix is equal to 0, so it can not be inverted

Esteemed Advisor
Posts: 6,684

Re: SAS Code Help - What am I doing wrong?

The error with INV is described here: http://support.sas.com/documentation/cdl/en/imlug/63541/HTML/default/viewer.htm#imlug_langref_sect15...

 

You need to define modules in IML before you can RUN them, this causes the notes.

I don't know if it is good to dive into IML when you are just starting out with learning SAS, but you should at least take a thorough look at the SAS/IML documentation (SAS/IML Overview).

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Grand Advisor
Posts: 9,584

Re: SAS Code Help - What am I doing wrong?

As LOG pointed out. Your matrix is singular. Such kind of matrix can't a inverse . ERROR: (execution) Matrix should be non-singular. And You'd better post it at IML forum, since it is IML code. And you don't need RUN in IML, but need a QUIT at the end of IML code.
Ask a Question
Discussion stats
  • 3 replies
  • 300 views
  • 0 likes
  • 4 in conversation