## SAS Code Help - What am I doing wrong?

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

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?

Frequent Contributor
Posts: 146

## 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

Super User
Posts: 10,217

## 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
How to convert datasets to data steps
How to post code
Super User
Posts: 10,770

## 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.
Discussion stats
• 3 replies
• 551 views
• 0 likes
• 4 in conversation