Hello Tom & PGStats, many thanks for your help ! based on the message from Tom, I have buil the following macro "listOfKNN": data observations; do ID=1 TO 100000; x1 = RAND('NORMAL',0,1); x2 = RAND('NORMAL',0,1); x3 = RAND('NORMAL',0,1); output; end; run; %macro listOfKNN (obser , target, K, nameOutput); %Let dim = %eval(%SYSFUNC(count(&target,%NRSTR( )))+1) ; %let ttt =; %DO ii = 1 %TO &dim; %let ttt = &ttt.(x&ii.-%scan(&target,&ii," "))**2; %IF &ii NE &dim %THEN %let ttt = &ttt.+; %END; proc sql noprint ; create table &nameOutput as select distinct *, sqrt(&ttt)as distance from &obser order by distance; quit; data &nameOutput; set &nameOutput (obs=&K); drop distance; run; %mend listOfKNN; /*make a test*/ %listOfKNN( obser = observations, target = 0.5 1 1, K = 5, nameOutput = out ); B.R. Olivier
... View more