现在我需要有一个限定条件就是,如果数据集B中的数据ID出现了超过了3次,那么这个ID就不再被计算在下一次计算距离的数据之内了。要怎么完成这个算法呢?
下面这个是我寻找两个数据集间,最短距离的一个大致方法。要如何改善才能把这个限制条件加进去呢??
Data RowLookUp(Keep = city StartRow EndRow) ;
Retain StartRow ;
Set B;
by city ;
if first.city then StartRow = _N_ ;
if last.city then do ;
EndRow = _N_ ;
Output ;
end ;
run ;
Data Match (Keep = House_id BestMatch BestDistance) ;
Array RQn(2:&NumQs) q2-q&NumQs ;
Array DQn(2:&NumQs) dq2-dq&NumQs ;
Retain BestMatch BestDistance ;
Merge A RowLookup ;
by city ;
do RowNum = StartRow to EndRow ;
Set B Point=RowNum ;
Distance = 0 ;
do i = 2 to &NumQs ;
Distance = Distance + ((RQn(i) - DQn(i))**2) ;
if Distance ge BestDistance then do ;
if RowNum ne StartRow then i = &NumQs+1 ;
end ;
end ;
if RowNum eq StartRow or Distance lt BestDistance then do ;
BestDistance = Distance ;
BestMatch = DHouse ;
end ;
end ;
Output ;
run ;
求各位大神帮忙。。。



雷达卡




京公网安备 11010802022788号







