<?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: SAS KNN - Extract Distance Measure in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/SAS-KNN-Extract-Distance-Measure/m-p/394799#M20627</link>
    <description>&lt;P&gt;You could concatenate datasetA and datasetB and extract a sub-matrix of the matrix provided by &lt;STRONG&gt;proc distance&lt;/STRONG&gt;.&lt;/P&gt;</description>
    <pubDate>Mon, 11 Sep 2017 18:01:58 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2017-09-11T18:01:58Z</dc:date>
    <item>
      <title>SAS KNN - Extract Distance Measure</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/SAS-KNN-Extract-Distance-Measure/m-p/394775#M20626</link>
      <description>&lt;P&gt;I am runing a KNN algorithm and would like to be able to extract the distance for each tested variable. For example, if the data is trained on Dataset A and tested on Dataset B, then what is the distance between a given record in Dataset B and its nearest neighbor in Dataset A. I am using the PROC DISCRIM procedure to execute this.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;DATA MASTER;
	INFILE DATALINES;
	INPUT k  errorrate;
	DATALINES;
RUN;

%macro KNND;
	%do i=1 %TO 50;
		%IF %SYSFUNC(MOD(&amp;amp;i,2))=1 %THEN %DO;

			PROC DISCRIM 
				DATA=TRAIN 
				TESTDATA=TEST
				TESTOUT=_score&amp;amp;i
				METHOD=NPAR
				K=&amp;amp;i;
				CLASS BAD;
				VAR VAR1 VAR2 VAR3 VAR4; 
			RUN; 

				PROC SQL noprint;
					CREATE TABLE stage&amp;amp;i AS 
						SELECT &amp;amp;i AS k,
						SUM(CASE WHEN BAD = _INTO_ THEN 0 ELSE 1 END)/COUNT(NIIN) AS errorrate
				FROM _score&amp;amp;i;
			QUIT;

			PROC APPEND BASE=MASTER DATA=stage&amp;amp;i;
			RUN; 


			%END;


%END; 

%MEND KNND;

%KNND&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Sep 2017 17:35:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/SAS-KNN-Extract-Distance-Measure/m-p/394775#M20626</guid>
      <dc:creator>macworthy</dc:creator>
      <dc:date>2017-09-11T17:35:11Z</dc:date>
    </item>
    <item>
      <title>Re: SAS KNN - Extract Distance Measure</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/SAS-KNN-Extract-Distance-Measure/m-p/394799#M20627</link>
      <description>&lt;P&gt;You could concatenate datasetA and datasetB and extract a sub-matrix of the matrix provided by &lt;STRONG&gt;proc distance&lt;/STRONG&gt;.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Sep 2017 18:01:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/SAS-KNN-Extract-Distance-Measure/m-p/394799#M20627</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-09-11T18:01:58Z</dc:date>
    </item>
  </channel>
</rss>

