Compute Mahalanobis Distance from a reference point

Reply
New Contributor
Posts: 2

Compute Mahalanobis Distance from a reference point

I Have 8 variables, (x1-x8) and 310 observations for each variable, with no missing observations.

I Need to compute Mahalanobis Distance from a reference point of (7,7,7,7,7,7,7,7).

I understand that Proc IML is the easiest method for this.  Can someone assist me with the SAS code necessary to do this?

thanks in advance.

PROC Star
Posts: 7,363

Re: Compute Mahalanobis Distance from a reference point

SAS Super FREQ
Posts: 3,476

Re: Compute Mahalanobis Distance from a reference point

SAS/IML 12.1 supports the MAHALANOBIS function.  If X is the data matrix, then do this:

center = {7 7 7 7 7 7 7 7};

md = mahalanobis(X, center);

New Contributor
Posts: 2

Re: Compute Mahalanobis Distance from a reference point

Oh, that is intuitively obvious.  Thanks.  One more question:

the data matrix would simoly be defined as:

X={x1 x2 x3 x4 x5 x6 x7 x8};

SAS Super FREQ
Posts: 3,476

Re: Compute Mahalanobis Distance from a reference point

That is the mathematical notation. The corresponding IML syntax would be

X = x1 || x2 || x3 || x4 ||x5 ||x6 || x7 || x8;

or alternatively:

varNames = "x1":"x8";

use MyData;

read all varNames into X;

close MyData;

Ask a Question
Discussion stats
  • 4 replies
  • 237 views
  • 3 likes
  • 3 in conversation