Hi there,
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.
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.
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).
%macro pmbr (run=1,method =scan, k=12);
*** create mandatory dmdb database for PROC PMBR *****************************;
proc dmdb
data=&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=&em_import_data
dmdbcat=_cat
method=scan
k=&k.;
score data=clusters_test out=score_pmbr_scan;
target %em_target ;
var %em_interval_input ;
ods output fitStatistics=fitStats&run.;
run;
data fitStats&run.;
length method $ 10;
length runLabel $ 64;
set fitStats&run.;
run = &run;
runLabel = "&runLabel";
method="&method.";
k=&k.;
run;
proc print data=fitStats&run.;
run;
proc append base=fitStats data=fitStats&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);
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.
I currently don't even know how to debug this =/ , just started using SAS EM.
Any help is appreciated!
A few changes to make:
1) You need to add the runlabel parameter to the %macro statement:
%macro pmbr (run=1, runLabel=, method =scan, k=12);
2) Need to remove " / level=level " from the VAR and TARGET statements in PROC DMDB.
3) I'm not sure what/where clusters_test data is, but using that causes an error for me after that.
4) I don't think PROC PMBR creates an ODS table FitStatistics
So I'm not sure this approach will work, but two things you can do to help figure out where your program is failing:
1) add
options mprint;
to the Project Start Code so your Log will be more helpful. And then...
2) View the Log in the Results of the SAS Code node after running it to see what errors are occurring.
A few changes to make:
1) You need to add the runlabel parameter to the %macro statement:
%macro pmbr (run=1, runLabel=, method =scan, k=12);
2) Need to remove " / level=level " from the VAR and TARGET statements in PROC DMDB.
3) I'm not sure what/where clusters_test data is, but using that causes an error for me after that.
4) I don't think PROC PMBR creates an ODS table FitStatistics
So I'm not sure this approach will work, but two things you can do to help figure out where your program is failing:
1) add
options mprint;
to the Project Start Code so your Log will be more helpful. And then...
2) View the Log in the Results of the SAS Code node after running it to see what errors are occurring.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Use this tutorial as a handy guide to weigh the pros and cons of these commonly used machine learning algorithms.
Find more tutorials on the SAS Users YouTube channel.