<?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 SAS Code to run KNN (PMBR) with multiple K's in SAS Enterprise Miner in SAS Data Science</title>
    <link>https://communities.sas.com/t5/SAS-Data-Science/SAS-Code-to-run-KNN-PMBR-with-multiple-K-s-in-SAS-Enterprise/m-p/471248#M7121</link>
    <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to use SAS Enterprise Miner to run KNN. My task is to run KNN with 20 different values for k and select the best K based on misclassification rates.&lt;/P&gt;&lt;P&gt;I definitely don't want to put 20 blocks in my diagram, so I decided to code it using the SAS Code block. This is the first time I'm using this block, so I guess I need some help, because my code below did not run.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the piece of code that I put inside a SAS block (the first proc dmdb I included after reading it was necessary for proc pmbr to run).&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro pmbr (run=1,method =scan, k=12);
*** create mandatory dmdb database for PROC PMBR *****************************; 
proc dmdb
	data=&amp;amp;em_import_data
	dmdbcat=work._cat;
   class %em_target;
	var %em_interval_input / level = interval;
   target %em_target / level = binary ;
run;
 
*** classify with PROC PMBR SCAN method **************************************; 

proc pmbr
	data=&amp;amp;em_import_data
	dmdbcat=_cat
	method=scan
	k=&amp;amp;k.; 
	score data=clusters_test out=score_pmbr_scan; 
	target %em_target ; 
	var %em_interval_input ;
   ods output fitStatistics=fitStats&amp;amp;run.;
 
run; 

data fitStats&amp;amp;run.;
     length method $ 10;
     length runLabel $ 64;
     set fitStats&amp;amp;run.;
     run = &amp;amp;run;
     runLabel = "&amp;amp;runLabel";
     method="&amp;amp;method.";
     k=&amp;amp;k.;
   run;
 

proc print data=fitStats&amp;amp;run.;
run;
 
proc append base=fitStats data=fitStats&amp;amp;run.;
run;
 
%mend pmbr;
 
%pmbr(run=1,runLabel=Scan k=1,method=scan,k=1);
%pmbr(run=2,runLabel=Scan k=2,method=scan,k=2);
%pmbr(run=3,runLabel=Scan k=3,method=scan,k=3);
%pmbr(run=4,runLabel=Scan k=4,method=scan,k=4);
%pmbr(run=5,runLabel=Scan k=5,method=scan,k=5);
%pmbr(run=6,runLabel=Scan k=6,method=scan,k=6);
%pmbr(run=7,runLabel=Scan k=7,method=scan,k=7);
%pmbr(run=8,runLabel=Scan k=8,method=scan,k=8);
%pmbr(run=9,runLabel=Scan k=9,method=scan,k=9);
%pmbr(run=10,runLabel=Scan k=10,method=scan,k=10);
%pmbr(run=11,runLabel=Scan k=11,method=scan,k=11);
%pmbr(run=12,runLabel=Scan k=12,method=scan,k=12);
%pmbr(run=13,runLabel=Scan k=13,method=scan,k=13);
%pmbr(run=14,runLabel=Scan k=14,method=scan,k=14);
%pmbr(run=15,runLabel=Scan k=15,method=scan,k=15);
%pmbr(run=16,runLabel=Scan k=16,method=scan,k=16);
%pmbr(run=17,runLabel=Scan k=17,method=scan,k=17);
%pmbr(run=18,runLabel=Scan k=18,method=scan,k=18);
%pmbr(run=19,runLabel=Scan k=19,method=scan,k=19);
%pmbr(run=20,runLabel=Scan k=20,method=scan,k=20);

 &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;So basically my diagram has the data block (I've attached the data - the 10 first columns are interval inputs and the 11th column is the binary target), a transform block to standardize the input variables and finally this SAS Code block with the code above.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I currently don't even know how to debug this =/ , just started using SAS EM.&lt;/P&gt;&lt;P&gt;Any help is appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 18 Jun 2018 22:01:10 GMT</pubDate>
    <dc:creator>marianaalcos</dc:creator>
    <dc:date>2018-06-18T22:01:10Z</dc:date>
    <item>
      <title>SAS Code to run KNN (PMBR) with multiple K's in SAS Enterprise Miner</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/SAS-Code-to-run-KNN-PMBR-with-multiple-K-s-in-SAS-Enterprise/m-p/471248#M7121</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to use SAS Enterprise Miner to run KNN. My task is to run KNN with 20 different values for k and select the best K based on misclassification rates.&lt;/P&gt;&lt;P&gt;I definitely don't want to put 20 blocks in my diagram, so I decided to code it using the SAS Code block. This is the first time I'm using this block, so I guess I need some help, because my code below did not run.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the piece of code that I put inside a SAS block (the first proc dmdb I included after reading it was necessary for proc pmbr to run).&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro pmbr (run=1,method =scan, k=12);
*** create mandatory dmdb database for PROC PMBR *****************************; 
proc dmdb
	data=&amp;amp;em_import_data
	dmdbcat=work._cat;
   class %em_target;
	var %em_interval_input / level = interval;
   target %em_target / level = binary ;
run;
 
*** classify with PROC PMBR SCAN method **************************************; 

proc pmbr
	data=&amp;amp;em_import_data
	dmdbcat=_cat
	method=scan
	k=&amp;amp;k.; 
	score data=clusters_test out=score_pmbr_scan; 
	target %em_target ; 
	var %em_interval_input ;
   ods output fitStatistics=fitStats&amp;amp;run.;
 
run; 

data fitStats&amp;amp;run.;
     length method $ 10;
     length runLabel $ 64;
     set fitStats&amp;amp;run.;
     run = &amp;amp;run;
     runLabel = "&amp;amp;runLabel";
     method="&amp;amp;method.";
     k=&amp;amp;k.;
   run;
 

proc print data=fitStats&amp;amp;run.;
run;
 
proc append base=fitStats data=fitStats&amp;amp;run.;
run;
 
%mend pmbr;
 
%pmbr(run=1,runLabel=Scan k=1,method=scan,k=1);
%pmbr(run=2,runLabel=Scan k=2,method=scan,k=2);
%pmbr(run=3,runLabel=Scan k=3,method=scan,k=3);
%pmbr(run=4,runLabel=Scan k=4,method=scan,k=4);
%pmbr(run=5,runLabel=Scan k=5,method=scan,k=5);
%pmbr(run=6,runLabel=Scan k=6,method=scan,k=6);
%pmbr(run=7,runLabel=Scan k=7,method=scan,k=7);
%pmbr(run=8,runLabel=Scan k=8,method=scan,k=8);
%pmbr(run=9,runLabel=Scan k=9,method=scan,k=9);
%pmbr(run=10,runLabel=Scan k=10,method=scan,k=10);
%pmbr(run=11,runLabel=Scan k=11,method=scan,k=11);
%pmbr(run=12,runLabel=Scan k=12,method=scan,k=12);
%pmbr(run=13,runLabel=Scan k=13,method=scan,k=13);
%pmbr(run=14,runLabel=Scan k=14,method=scan,k=14);
%pmbr(run=15,runLabel=Scan k=15,method=scan,k=15);
%pmbr(run=16,runLabel=Scan k=16,method=scan,k=16);
%pmbr(run=17,runLabel=Scan k=17,method=scan,k=17);
%pmbr(run=18,runLabel=Scan k=18,method=scan,k=18);
%pmbr(run=19,runLabel=Scan k=19,method=scan,k=19);
%pmbr(run=20,runLabel=Scan k=20,method=scan,k=20);

 &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;So basically my diagram has the data block (I've attached the data - the 10 first columns are interval inputs and the 11th column is the binary target), a transform block to standardize the input variables and finally this SAS Code block with the code above.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I currently don't even know how to debug this =/ , just started using SAS EM.&lt;/P&gt;&lt;P&gt;Any help is appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jun 2018 22:01:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/SAS-Code-to-run-KNN-PMBR-with-multiple-K-s-in-SAS-Enterprise/m-p/471248#M7121</guid>
      <dc:creator>marianaalcos</dc:creator>
      <dc:date>2018-06-18T22:01:10Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Code to run KNN (PMBR) with multiple K's in SAS Enterprise Miner</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/SAS-Code-to-run-KNN-PMBR-with-multiple-K-s-in-SAS-Enterprise/m-p/475727#M7159</link>
      <description>&lt;P&gt;A few changes to make:&lt;/P&gt;
&lt;P&gt;1) You need to add the runlabel parameter to the %macro statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token macrobound"&gt;%macro&lt;/SPAN&gt; pmbr &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;, &lt;STRONG&gt;runLabel=, &lt;/STRONG&gt;&lt;/SPAN&gt;method &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;scan&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; k&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;12&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;2)&amp;nbsp; Need to remove "&amp;nbsp;&lt;STRONG&gt;/ level=&lt;EM&gt;level&amp;nbsp;&lt;/EM&gt;&lt;/STRONG&gt;" from the VAR and TARGET statements in PROC DMDB.&lt;/P&gt;
&lt;P&gt;3) I'm not sure what/where clusters_test data is, but using that causes an error for me after that.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;4) I don't think PROC PMBR creates an ODS table FitStatistics&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I'm not sure this approach will work, but two things you can do to help figure out where your program is failing:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) add&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;options mprint;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;to the Project Start Code so your Log will be more helpful.&amp;nbsp; And then...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) View the Log in the Results of the SAS Code node after running it to see what errors are occurring.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jul 2018 16:29:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/SAS-Code-to-run-KNN-PMBR-with-multiple-K-s-in-SAS-Enterprise/m-p/475727#M7159</guid>
      <dc:creator>WendyCzika</dc:creator>
      <dc:date>2018-07-05T16:29:49Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Code to run KNN (PMBR) with multiple K's in SAS Enterprise Miner</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/SAS-Code-to-run-KNN-PMBR-with-multiple-K-s-in-SAS-Enterprise/m-p/478083#M7181</link>
      <description>Thanks for all valuable info Wendy! I was able to make it run!</description>
      <pubDate>Sat, 14 Jul 2018 01:33:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/SAS-Code-to-run-KNN-PMBR-with-multiple-K-s-in-SAS-Enterprise/m-p/478083#M7181</guid>
      <dc:creator>marianaalcos</dc:creator>
      <dc:date>2018-07-14T01:33:26Z</dc:date>
    </item>
  </channel>
</rss>

