<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Distance between two data set in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Distance-between-two-data-set/m-p/267413#M2716</link>
    <description>OK. No problem.

&lt;PRE&gt;
Data have1;
Input obs reps id $ x  y;
Datalines ;
1
1
00-01
5
3
2
1
00-02
4
6
3
1
00-03
6
4
4
1
00-06
4
6
5
2
00-02
4
6
6
2
00-03
6
4
7
2
00-04
7
5
8
2
00-05
9
2
9
3
00-01
5
3
10
3
00-02
4
6
11
3
00-05
9
2
12
3
00-10
7
4
13
4
00-03
6
4
14
4
00-05
9
2
15
4
00-09
7
3
16
4
00-10
7
4
17
5
00-03
6
4
18
5
00-04
7
5
19
5
00-07
5
8
20
5
00-09
7
3
21
6
00-02
4
6
22
6
00-03
6
4
23
6
00-05
9
2
24
6
00-10
7
4
;
run;
Data have2;
Input obs reps id $ x y;
Datalines ;
25
7
00-01
5
3
26
7
00-08
1
8
27
7
00-09
7
3
28
7
00-10
7
4
;
Run;

proc iml;
use have1 nobs nobs;
read all var {reps};
read all var {x y} into data;
close;
use have2;
read all var {x y} into m;
close;

center=m[:,];
level=unique(reps);
want=j(ncol(level),4,.); 

do i=1 to ncol(level);
 want[i,1]=level[i];
 idx=loc(reps=level[i]);
 want[i,2:3]=data[idx,][:,];
end;
 
 xx=want[,2:3];
 cov=cov(xx);
 want[,4]= mahalanobis(xx,center,cov);

create want from want[c={reps  x y distance}];
append from want;
close;

quit;


&lt;/PRE&gt;</description>
    <pubDate>Sat, 30 Apr 2016 13:14:34 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2016-04-30T13:14:34Z</dc:date>
    <item>
      <title>Distance between two data set</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Distance-between-two-data-set/m-p/267362#M2711</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here are two data sets:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data have1;&lt;/P&gt;
&lt;P&gt;Input obs reps id $ x&amp;nbsp; y;&lt;/P&gt;
&lt;P&gt;Datalines ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;&lt;STRONG&gt;Obs&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&lt;STRONG&gt;REPS&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&lt;STRONG&gt;ID&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&lt;STRONG&gt;X&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&lt;STRONG&gt;Y&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;00-01&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;5&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;3&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;&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lt;P&gt;3&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;&lt;STRONG&gt;28&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;7&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;00-10&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;7&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;4&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;Run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Dataset HAVE1 has 6 replicates indicated by variable REPS. I want to compute the Mahalanobis distance between the center of HAVE2 and each of the REPS in HAVE1. The vector of means of x and y in each of the datasets can serve as the center of each of the datasets. The distance will then added to columns in HAVE1. Does any know how to proceed?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jack&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Apr 2016 23:40:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Distance-between-two-data-set/m-p/267362#M2711</guid>
      <dc:creator>SWEETSAS</dc:creator>
      <dc:date>2016-04-29T23:40:19Z</dc:date>
    </item>
    <item>
      <title>Re: Distance between two data set</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Distance-between-two-data-set/m-p/267368#M2712</link>
      <description>&lt;P&gt;Break it into parts.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Calculate centroids - proc means&lt;/P&gt;
&lt;P&gt;2. Merge datasets&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3. Calculate distance&lt;/P&gt;</description>
      <pubDate>Sat, 30 Apr 2016 00:59:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Distance-between-two-data-set/m-p/267368#M2712</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-04-30T00:59:45Z</dc:date>
    </item>
    <item>
      <title>Re: Distance between two data set</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Distance-between-two-data-set/m-p/267379#M2713</link>
      <description>So means of x and y in HAVE2 is the center of Mahalanobis distance ?




&lt;PRE&gt;
Data have1;
Input obs reps id $ x  y;
Datalines ;
1
1
00-01
5
3
2
1
00-02
4
6
3
1
00-03
6
4
4
1
00-06
4
6
5
2
00-02
4
6
6
2
00-03
6
4
7
2
00-04
7
5
8
2
00-05
9
2
9
3
00-01
5
3
10
3
00-02
4
6
11
3
00-05
9
2
12
3
00-10
7
4
13
4
00-03
6
4
14
4
00-05
9
2
15
4
00-09
7
3
16
4
00-10
7
4
17
5
00-03
6
4
18
5
00-04
7
5
19
5
00-07
5
8
20
5
00-09
7
3
21
6
00-02
4
6
22
6
00-03
6
4
23
6
00-05
9
2
24
6
00-10
7
4
;
run;
Data have2;
Input obs reps id $ x y;
Datalines ;
25
7
00-01
5
3
26
7
00-08
1
8
27
7
00-09
7
3
28
7
00-10
7
4
;
Run;

proc iml;
use have1 nobs nobs;
read all var {obs reps id x  y};
read all var {x y} into data;
close;
use have2;
read all var {x y} into m;
close;

center=m[:,];
start_end=t(loc(t(reps)^={.}||remove(reps,nobs)))||
          t(loc(t(reps)^=remove(reps,1)||{.}));
distance=j(nrow(reps),1,.); 

do i=1 to nrow(start_end);
 idx=start_end[i,1]:start_end[i,2];
 xx=data[idx,];
 cov=cov(xx);
 distance[idx]= mahalanobis(xx,center,cov);
end;

create want var {obs reps id x y distance};
append;
close;

quit;
&lt;/PRE&gt;</description>
      <pubDate>Sat, 30 Apr 2016 03:45:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Distance-between-two-data-set/m-p/267379#M2713</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-04-30T03:45:30Z</dc:date>
    </item>
    <item>
      <title>Re: Distance between two data set</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Distance-between-two-data-set/m-p/267401#M2714</link>
      <description>&lt;BR /&gt;So means of x and y in HAVE2 is the center of Mahalanobis distance ? &lt;BR /&gt;&lt;BR /&gt;Yes. HAVE2 is the center of Mahalanobis distance.</description>
      <pubDate>Sat, 30 Apr 2016 10:52:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Distance-between-two-data-set/m-p/267401#M2714</guid>
      <dc:creator>SWEETSAS</dc:creator>
      <dc:date>2016-04-30T10:52:41Z</dc:date>
    </item>
    <item>
      <title>Re: Distance between two data set</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Distance-between-two-data-set/m-p/267408#M2715</link>
      <description>&lt;P&gt;Thanks very much Ksharp for sharing the program.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The program works, but it's computing dintance from each observation in HAVE1 to the mean of the variables in HAVE2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But what I want to compute is the Mahalonobis distance from the means of the variables in each replicate in HAVE1 to the means of the variables in HAVE2, so that when the column containing distance is added back to HAVE1, it should be one value of distance for each replicate. This is because the distance is computed from the means of the variables in each replicate in HAVE1 which are unique to each replicate.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;J&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 30 Apr 2016 12:40:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Distance-between-two-data-set/m-p/267408#M2715</guid>
      <dc:creator>SWEETSAS</dc:creator>
      <dc:date>2016-04-30T12:40:11Z</dc:date>
    </item>
    <item>
      <title>Re: Distance between two data set</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Distance-between-two-data-set/m-p/267413#M2716</link>
      <description>OK. No problem.

&lt;PRE&gt;
Data have1;
Input obs reps id $ x  y;
Datalines ;
1
1
00-01
5
3
2
1
00-02
4
6
3
1
00-03
6
4
4
1
00-06
4
6
5
2
00-02
4
6
6
2
00-03
6
4
7
2
00-04
7
5
8
2
00-05
9
2
9
3
00-01
5
3
10
3
00-02
4
6
11
3
00-05
9
2
12
3
00-10
7
4
13
4
00-03
6
4
14
4
00-05
9
2
15
4
00-09
7
3
16
4
00-10
7
4
17
5
00-03
6
4
18
5
00-04
7
5
19
5
00-07
5
8
20
5
00-09
7
3
21
6
00-02
4
6
22
6
00-03
6
4
23
6
00-05
9
2
24
6
00-10
7
4
;
run;
Data have2;
Input obs reps id $ x y;
Datalines ;
25
7
00-01
5
3
26
7
00-08
1
8
27
7
00-09
7
3
28
7
00-10
7
4
;
Run;

proc iml;
use have1 nobs nobs;
read all var {reps};
read all var {x y} into data;
close;
use have2;
read all var {x y} into m;
close;

center=m[:,];
level=unique(reps);
want=j(ncol(level),4,.); 

do i=1 to ncol(level);
 want[i,1]=level[i];
 idx=loc(reps=level[i]);
 want[i,2:3]=data[idx,][:,];
end;
 
 xx=want[,2:3];
 cov=cov(xx);
 want[,4]= mahalanobis(xx,center,cov);

create want from want[c={reps  x y distance}];
append from want;
close;

quit;


&lt;/PRE&gt;</description>
      <pubDate>Sat, 30 Apr 2016 13:14:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Distance-between-two-data-set/m-p/267413#M2716</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-04-30T13:14:34Z</dc:date>
    </item>
    <item>
      <title>Re: Distance between two data set</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Distance-between-two-data-set/m-p/267415#M2717</link>
      <description>&lt;P&gt;Thanks! Thanks!! Thanks!!!. It's perfect!!!!!!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please, I have a few questions on some parts of the code to enable me generalise the code to handle any number of variables: This is because a data set can have any number of variable--not just x and y; So that I will use something like &amp;amp;varlist.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;want=j(ncol(level),4,.); What is the 4 doing; I assume is the number of observation in each replicate, right? Or is it the 4th column?&lt;/P&gt;
&lt;P&gt;do i=1 to ncol(level);&lt;BR /&gt; want[i,1]=level[i];&lt;BR /&gt; idx=loc(reps=level[i]);&lt;BR /&gt; want[i,2:3]=data[idx,][:,]; What is the 2:3 doing? is it indexing column 2 to 3? If yes, in which data set?&lt;BR /&gt;end;&lt;BR /&gt; &lt;BR /&gt; xx=want[,2:3]; what is the 2:3 doing?&lt;BR /&gt; cov=cov(xx);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for you incredible help,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;J&lt;BR /&gt; want[,4]= mahalanobis(xx,center,cov); What is the 4 doing?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks very much for your help.&lt;/P&gt;</description>
      <pubDate>Sat, 30 Apr 2016 14:15:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Distance-between-two-data-set/m-p/267415#M2717</guid>
      <dc:creator>SWEETSAS</dc:creator>
      <dc:date>2016-04-30T14:15:57Z</dc:date>
    </item>
    <item>
      <title>Re: Distance between two data set</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Distance-between-two-data-set/m-p/267426#M2718</link>
      <description>&lt;PRE&gt;
OK. This code you don't need to consider about the number of variables.
Just define the calculated variables(x y ........ ) at :

read all var {x y .........} into data[c=vnames];

and Here :
read all var {x y ........} into m;





Data have1;
Input obs reps id $ x  y;
Datalines ;
1
1
00-01
5
3
2
1
00-02
4
6
3
1
00-03
6
4
4
1
00-06
4
6
5
2
00-02
4
6
6
2
00-03
6
4
7
2
00-04
7
5
8
2
00-05
9
2
9
3
00-01
5
3
10
3
00-02
4
6
11
3
00-05
9
2
12
3
00-10
7
4
13
4
00-03
6
4
14
4
00-05
9
2
15
4
00-09
7
3
16
4
00-10
7
4
17
5
00-03
6
4
18
5
00-04
7
5
19
5
00-07
5
8
20
5
00-09
7
3
21
6
00-02
4
6
22
6
00-03
6
4
23
6
00-05
9
2
24
6
00-10
7
4
;
run;
Data have2;
Input obs reps id $ x y;
Datalines ;
25
7
00-01
5
3
26
7
00-08
1
8
27
7
00-09
7
3
28
7
00-10
7
4
;
Run;

proc iml;
use have1 nobs nobs;
read all var {reps};
read all var {x y} into data[c=vnames];
close;
use have2;
read all var {x y} into m;
close;

center=m[:,];
level=unique(reps);
want=j(ncol(level),ncol(data)+2,.); 

do i=1 to ncol(level);
 want[i,1]=level[i];
 idx=loc(reps=level[i]);
 want[i,2:ncol(data)+1]=data[idx,][:,];
end;
 
 xx=want[,2:ncol(data)+1];
 cov=cov(xx);
 want[,ncol(data)+2]= mahalanobis(xx,center,cov);

names={reps}||vnames||{distance};
create want from want[c=names];
append from want;
close;

quit;

&lt;/PRE&gt;</description>
      <pubDate>Sat, 30 Apr 2016 16:41:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Distance-between-two-data-set/m-p/267426#M2718</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-04-30T16:41:17Z</dc:date>
    </item>
    <item>
      <title>Re: Distance between two data set</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Distance-between-two-data-set/m-p/267521#M2721</link>
      <description>&lt;P&gt;The program worked as expected and computes the Mahalanobis distance when the numbers are not standardized.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, when the numbers are standardized it gives an error and stops. The error is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"ERROR: (execution) Matrix should be non-singular."&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suspect it's because one should be computing Euclidian distance when the numbers are standardized since standardized variables invlove identity matrix. Does anyone know why this is the case and how this may overcome in computing distance for standardized variables?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help is appreciated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;J&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 May 2016 00:44:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Distance-between-two-data-set/m-p/267521#M2721</guid>
      <dc:creator>SWEETSAS</dc:creator>
      <dc:date>2016-05-02T00:44:35Z</dc:date>
    </item>
    <item>
      <title>Re: Distance between two data set</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Distance-between-two-data-set/m-p/267531#M2722</link>
      <description>&lt;PRE&gt;
I think if they were standardized variables. You don't need calculated Mahalanobis distance,  Euclidian distance is right enough.
Mahalanobis distance is about firstly standardized  multi-dimension(multi-variables) data and calculated  Euclidian distance between them.

More info Check Rick's blog about Mahalanobis distance:
http://blogs.sas.com/content/iml/2012/02/15/what-is-mahalanobis-distance.html

And can you post full LOG information?


&lt;/PRE&gt;</description>
      <pubDate>Mon, 02 May 2016 03:30:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Distance-between-two-data-set/m-p/267531#M2722</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-05-02T03:30:43Z</dc:date>
    </item>
    <item>
      <title>Re: Distance between two data set</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Distance-between-two-data-set/m-p/267556#M2724</link>
      <description>&lt;P&gt;below is the log:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or could it be that it's because HAVE2 &amp;nbsp;is only the mean values? The actual aim is to compute distance between of the datasets in each replicate in HAVE1 to the dataset HAVE2. I have only use the mean of HAVE2 becuase I thought that the center should be sufficient. It could be that it's because we are using only the covariance of HAVE1 instead of the pooled covariance of each of the replicate in HAVE1 and HAVE2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;Below is the SAS log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;270 proc iml;&lt;BR /&gt;NOTE: IML Ready&lt;BR /&gt;271 use stdwant nobs nobs;&lt;BR /&gt;272 read all var {reps};&lt;BR /&gt;273 read all var {x y} into data[c=vnames];&lt;BR /&gt;274 close;&lt;BR /&gt;NOTE: Closing WORK.STDWANT&lt;BR /&gt;275 use stdhave;&lt;BR /&gt;276 read all var {x y} into m;&lt;BR /&gt;277 close;&lt;BR /&gt;NOTE: Closing WORK.STDHAVE&lt;BR /&gt;278&lt;BR /&gt;279 center=m[:,];&lt;BR /&gt;280 level=unique(reps);&lt;BR /&gt;281 want=j(ncol(level),ncol(data)+2,.);&lt;BR /&gt;282&lt;BR /&gt;283 do i=1 to ncol(level);&lt;BR /&gt;284 want[i,1]=level[i];&lt;BR /&gt;285 idx=loc(reps=level[i]);&lt;BR /&gt;286 want[i,2:ncol(data)+1]=data[idx,][:,];&lt;BR /&gt;287 end;&lt;BR /&gt;288&lt;BR /&gt;289 xx=want[,2:ncol(data)+1];&lt;BR /&gt;290 cov=cov(xx);&lt;BR /&gt;291 want[,ncol(data)+2]= mahalanobis(xx,center,cov);&lt;BR /&gt;NOTE: Module MAHALANOBIS loaded from the storage SASHELP.IMLMLIB.&lt;BR /&gt;ERROR: (execution) Matrix should be non-singular.&lt;/P&gt;
&lt;P&gt;operation : TRISOLV at offset 8 column 18&lt;BR /&gt; operands : *LIT1242, U, _TEM1001&lt;/P&gt;
&lt;P&gt;*LIT1242 1 row 1 col (numeric)&lt;/P&gt;
&lt;P&gt;2&lt;/P&gt;
&lt;P&gt;U 2 rows 2 cols (numeric)&lt;/P&gt;
&lt;P&gt;0 0&lt;BR /&gt; 0 0&lt;BR /&gt;_TEM1001 2 rows 30 cols (numeric)&lt;/P&gt;
&lt;P&gt;statement : ASSIGN at offset 8 column 7&lt;BR /&gt; traceback : module MAHALANOBIS at offset 8 column 7&lt;/P&gt;
&lt;P&gt;NOTE: Paused in module MAHALANOBIS.&lt;BR /&gt;292&lt;BR /&gt;293 names={reps}||vnames||{distance};&lt;BR /&gt;294 create want from want[c=names];&lt;BR /&gt;ERROR: Matrix want has not been set to a value.&lt;/P&gt;
&lt;P&gt;statement : CREATE at line 294 column 1&lt;BR /&gt;295 append from want;&lt;BR /&gt;ERROR: No data set is currently open for output.&lt;/P&gt;
&lt;P&gt;statement : APPEND at line 295 column 1&lt;BR /&gt;296 close;&lt;BR /&gt;297&lt;BR /&gt;298 quit;&lt;BR /&gt;NOTE: Exiting IML.&lt;BR /&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;NOTE: PROCEDURE IML used (Total process time):&lt;BR /&gt; real time 0.02 seconds&lt;BR /&gt; cpu time 0.04 seconds&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 May 2016 09:46:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Distance-between-two-data-set/m-p/267556#M2724</guid>
      <dc:creator>SWEETSAS</dc:creator>
      <dc:date>2016-05-02T09:46:27Z</dc:date>
    </item>
    <item>
      <title>Re: Distance between two data set</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Distance-between-two-data-set/m-p/267592#M2725</link>
      <description>&lt;A href="http://people.revoledu.com/kardi/tutorial/Similarity/MahalanobisDistance.html" target="_blank"&gt;http://people.revoledu.com/kardi/tutorial/Similarity/MahalanobisDistance.html&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;The above link contains exactly what I want to do. That is to compute distance between two matrix. In my case HAVE1 and HAVE2. The only difference is that HAVE1 have multiple data set in it, so I am computing distance between each of those replicate in HAVE1 and HAVE2. In the link above, the data were standardized and that didnt cause any problem. The site provide MATLAB code. But I want it in SAS.&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;&lt;BR /&gt;J&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 02 May 2016 13:17:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Distance-between-two-data-set/m-p/267592#M2725</guid>
      <dc:creator>SWEETSAS</dc:creator>
      <dc:date>2016-05-02T13:17:19Z</dc:date>
    </item>
    <item>
      <title>Re: Distance between two data set</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Distance-between-two-data-set/m-p/267600#M2726</link>
      <description>&lt;P&gt;I don't think this latest issue has anything to do with whether the variables are standardized. If you standardize a variable, it merely centers data and scales the data to unit variance.&amp;nbsp; That makes the covariance matrix equal to the correlation matrix of the unstandardized data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suspect that you have degenerate data for one of the subgroups.&amp;nbsp; For example, constant data is degenerate because it has no variance.&lt;/P&gt;
&lt;P&gt;In general, any collinear&amp;nbsp;data has a singular covariance matrix and is degenerate.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Print the data for the group that is giving you problems. I think you'll find that it is degenerate.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;[BTW, the Mahalanobis distance is different from the Euclidean distance unless the covariance matrix equals the identity matrix.]&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 May 2016 13:33:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Distance-between-two-data-set/m-p/267600#M2726</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2016-05-02T13:33:26Z</dc:date>
    </item>
    <item>
      <title>Re: Distance between two data set</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Distance-between-two-data-set/m-p/267610#M2728</link>
      <description>Thanks Rick. You are right. It seems that the issue comes from my using the means of each subgroups in HAVE1 to form  distance with the mean of HAVE2. So that with standardization, the mean of each subgroup essentially supposed to be zero. With unit variance.&lt;BR /&gt;&lt;BR /&gt;The way to avoid this is to use the observations in the subgroubs instead of using the means. Similarly for HAVE2, using the observations instead of the mean. That is form the distance between the data sets in HAVE1 (each of the subgroups) and HAVE2 data set.&lt;BR /&gt;&lt;BR /&gt;The link below does that using MATLB: that is what I wanted to do. Except that in my own case I will be forming distance between subgroups and one data set.&lt;BR /&gt;&lt;BR /&gt;Thanks J&lt;BR /&gt;&lt;BR /&gt; &lt;A href="http://people.revoledu.com/kardi/tutorial/Similarity/MahalanobisDistance.html" target="_blank"&gt;http://people.revoledu.com/kardi/tutorial/Similarity/MahalanobisDistance.html&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 02 May 2016 14:16:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Distance-between-two-data-set/m-p/267610#M2728</guid>
      <dc:creator>SWEETSAS</dc:creator>
      <dc:date>2016-05-02T14:16:08Z</dc:date>
    </item>
    <item>
      <title>Re: Distance between two data set</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Distance-between-two-data-set/m-p/267814#M2731</link>
      <description>HaHa. I know what is going on after testing the example in URL you gave.
Matlab's mahalanobis distance is totally different than SAS's . and even more COV() in matlab(DF is n) is different than SAS's(DF is n-1) either . I rewrite it again by IML . Check it .

&lt;PRE&gt;


proc iml;

A={2  2,
   2  5,
   6  5,
   7  3,
   4  7,
   6  4,
   5  3,
   4  6,
   2  5,
   1  3};
                  
B={6  5,
   7  4,
   8  7,
   5  6,
   5  4};
   
   
start new_cov(x);
 Xc=x-x[:,];
 c=Xc`*Xc/nrow(x);
 return (c);
finish;   
   
start new_mahalanobis(A,B);
 xDiff=A[:,]-B[:,];  
 cA=new_cov(A);
 cB=new_cov(B);
 pC=(nrow(A)/(nrow(A)+nrow(B)))#cA +
    (nrow(B)/(nrow(A)+nrow(B)))#cB ;
 d=sqrt(xDiff*inv(pC)*xDiff`); 
 return (d);
finish;
                    
 dis=new_mahalanobis(A,B);
print dis;
quit;

&lt;/PRE&gt;</description>
      <pubDate>Tue, 03 May 2016 05:30:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Distance-between-two-data-set/m-p/267814#M2731</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-05-03T05:30:46Z</dc:date>
    </item>
    <item>
      <title>Re: Distance between two data set</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Distance-between-two-data-set/m-p/267817#M2732</link>
      <description>Here is what I got according to your posted URL. Enjoy!

&lt;PRE&gt;
Data have1;
Input obs reps id $ x  y;
Datalines ;
1
1
00-01
5
3
2
1
00-02
4
6
3
1
00-03
6
4
4
1
00-06
4
6
5
2
00-02
4
6
6
2
00-03
6
4
7
2
00-04
7
5
8
2
00-05
9
2
9
3
00-01
5
3
10
3
00-02
4
6
11
3
00-05
9
2
12
3
00-10
7
4
13
4
00-03
6
4
14
4
00-05
9
2
15
4
00-09
7
3
16
4
00-10
7
4
17
5
00-03
6
4
18
5
00-04
7
5
19
5
00-07
5
8
20
5
00-09
7
3
21
6
00-02
4
6
22
6
00-03
6
4
23
6
00-05
9
2
24
6
00-10
7
4
;
run;
Data have2;
Input obs reps id $ x y;
Datalines ;
25
7
00-01
5
3
26
7
00-08
1
8
27
7
00-09
7
3
28
7
00-10
7
4
;
Run;

proc iml;
use have1 nobs nobs;
read all var {reps};
read all var {x y} into data;
close;
use have2;
read all var {x y} into B;
close;

  
start new_cov(x);
 Xc=x-x[:,];
 c=Xc`*Xc/nrow(x);
 return (c);
finish;   
   
start new_mahalanobis(A,B);
 xDiff=A[:,]-B[:,];  
 cA=new_cov(A);
 cB=new_cov(B);
 pC=(nrow(A)/(nrow(A)+nrow(B)))#cA +
    (nrow(B)/(nrow(A)+nrow(B)))#cB ;
 d=sqrt(xDiff*inv(pC)*xDiff`); 
 return (d);
finish;



start_end=t(loc(t(reps)^={.}||remove(reps,nobs)))||
          t(loc(t(reps)^=remove(reps,1)||{.}));
want=j(nrow(start_end),2,.);
 
want[,1]=reps[start_end[,1]]; 
do i=1 to nrow(start_end);
 idx=start_end[i,1]:start_end[i,2];
 A=data[idx,];
 want[i,2]=new_mahalanobis(A,B);
end;

create want from want[c={reps distance}];
append from want;
close;
quit;


&lt;/PRE&gt;</description>
      <pubDate>Tue, 03 May 2016 05:42:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Distance-between-two-data-set/m-p/267817#M2732</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-05-03T05:42:03Z</dc:date>
    </item>
    <item>
      <title>Re: Distance between two data set</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Distance-between-two-data-set/m-p/268264#M2741</link>
      <description>Ksharp, awesome!! Thanks. You are indeed a genius.&lt;BR /&gt;I am very grateful for help and patience.&lt;BR /&gt;Thanks&lt;BR /&gt;&lt;BR /&gt;Jack</description>
      <pubDate>Wed, 04 May 2016 12:57:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Distance-between-two-data-set/m-p/268264#M2741</guid>
      <dc:creator>SWEETSAS</dc:creator>
      <dc:date>2016-05-04T12:57:27Z</dc:date>
    </item>
    <item>
      <title>Re: Distance between two data set</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Distance-between-two-data-set/m-p/268410#M2742</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I think it again. You are right. It is all about &lt;STRONG&gt;Covariate matrix of mahalanobis&lt;/STRONG&gt;. Which&amp;nbsp;is totally different between Matlab and SAS. Eevn more the function COV() is also a little different between Matlab and SAS. If you want stick with SAS's function , see the following code and it will lead you to the similiar result with Matlab .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have1;
Input obs reps id $ x  y;
Datalines ;
1
1
00-01
5
3
2
1
00-02
4
6
3
1
00-03
6
4
4
1
00-06
4
6
5
2
00-02
4
6
6
2
00-03
6
4
7
2
00-04
7
5
8
2
00-05
9
2
9
3
00-01
5
3
10
3
00-02
4
6
11
3
00-05
9
2
12
3
00-10
7
4
13
4
00-03
6
4
14
4
00-05
9
2
15
4
00-09
7
3
16
4
00-10
7
4
17
5
00-03
6
4
18
5
00-04
7
5
19
5
00-07
5
8
20
5
00-09
7
3
21
6
00-02
4
6
22
6
00-03
6
4
23
6
00-05
9
2
24
6
00-10
7
4
;
run;
Data have2;
Input obs reps id $ x y;
Datalines ;
25
7
00-01
5
3
26
7
00-08
1
8
27
7
00-09
7
3
28
7
00-10
7
4
;
Run;

proc iml;
use have1 nobs nobs;
read all var {reps};
read all var {x y} into data;
close;
use have2;
read all var {x y} into B;
close;

center=B[:,];
cB=cov(B);
start_end=t(loc(t(reps)^={.}||remove(reps,nobs)))||
          t(loc(t(reps)^=remove(reps,1)||{.}));
want=j(nrow(start_end),2,.);
 
want[,1]=reps[start_end[,1]]; 
do i=1 to nrow(start_end);
 idx=start_end[i,1]:start_end[i,2];
 A=data[idx,];
 mA=A[:,];
 cA=cov(A);
 cov=(nrow(A)/(nrow(A)+nrow(B)))#cA +
     (nrow(B)/(nrow(A)+nrow(B)))#cB ;
 want[i,2]=mahalanobis(mA,center,cov);
end;

create want from want[c={reps distance}];
append from want;
close;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 05 May 2016 01:07:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Distance-between-two-data-set/m-p/268410#M2742</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-05-05T01:07:24Z</dc:date>
    </item>
    <item>
      <title>Re: Distance between two data set</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Distance-between-two-data-set/m-p/268420#M2743</link>
      <description>Thanks. I prefer to stick with SAS function because I am more comfortable with SAS. Morever, With SAS function, it easier to do repetition to obtain sampling distribution. That is, it is easiet to write a program that will do compute such distance many times. The way we will have a third column containing the repl</description>
      <pubDate>Thu, 05 May 2016 01:45:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Distance-between-two-data-set/m-p/268420#M2743</guid>
      <dc:creator>SWEETSAS</dc:creator>
      <dc:date>2016-05-05T01:45:29Z</dc:date>
    </item>
    <item>
      <title>Re: Distance between two data set</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Distance-between-two-data-set/m-p/268422#M2744</link>
      <description>That is we have three variable: sampleID, replicate distance. &lt;BR /&gt;&lt;BR /&gt;I am realy very grateful for your patients and assistance. I have been trying to figure this for over 3 years now. Thanks again &lt;BR /&gt;&lt;BR /&gt;J</description>
      <pubDate>Thu, 05 May 2016 01:51:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Distance-between-two-data-set/m-p/268422#M2744</guid>
      <dc:creator>SWEETSAS</dc:creator>
      <dc:date>2016-05-05T01:51:03Z</dc:date>
    </item>
  </channel>
</rss>

