| 
 | 
沙发
 
 
 楼主 |
发表于 2004-6-1 05:48:10
|
只看该作者
 
 
 
try
For your data set, the following program will work. 
 
[code:1b10c]proc sql; 
create table center as 
select cat, mean(x) as mx, mean(y) as my, mean(z) as mz 
from tem 
group by cat 
order by cat; 
quit; 
 
proc sql; 
create table temp as 
select t.*, 
       sqrt((t.x-m1.mx)**2+(t.y-m1.my)**2+(t.z-m1.mz)**2) as di1, 
       sqrt((t.x-m2.mx)**2+(t.y-m2.my)**2+(t.z-m2.mz)**2) as di2, 
       sqrt((t.x-m3.mx)**2+(t.y-m3.my)**2+(t.z-m3.mz)**2) as di3 
from tem t 
left join center m1 
on m1.cat=1 
left join center m2 
on m2.cat=2 
left join center m3 
on m3.cat=3 
order by id; 
quit;[/code:1b10c] 
 
I did not consider the efficiency.  If you would like to consider the efficiancy, they key is not the number of the records, but the number of categories do you have.  It is possible to omit the second step, but using data step skill to do it.  Please read the documentation of SET statement, you may need two SET statement in one data step to combine the information from TEM and CENTER. |   
 
 
 
 |