the macro for binning of decision tree function included in sas is below:
%macro en();
data test_num;
set mywork.train(drop = survived);
run;
data num;
set sashelp.vcolumn;
where memname = 'TEST_NUM' and libname = 'WORK' and type = 'num';
run;
proc sql noprint;
select name into:numname separated by ' ' from num;
quit;
%let i = 1;
%do %until(%scan(&numname.,&i.,' ')=);
%let numnamei = %scan(&numname.,&i.,' ' );
ods graphics on;
proc hpsplit data= mywork.train intervalbins=100 leafsize=1000 maxbranch=5 MAXDEPTH=4 Missing=SIMILARITY;
target survived;
input &numnamei./ level=int;
output =tem1_&numnamei.
importance=temp2_&numnamei.
nodestats=temp3_&numnamei.
prunesubtree=temp4_&numnamei.;
run;
data tu_&numnamei.;
set temp3_&numnamei.;
if DEPTH = 0 then delete;
rt_&numnamei.=input(level0,8.8);
run ;
proc sgplot data=tu_&numnamei. ;
yaxis label="fenbu" min=0 max=4000;
vbar DECISION/response=n BARWIDTH=0.5 transparency=0.5;
vline DECISION/response=rt_&numnamei. y2axis lineattrs=(color=red );
symbol color=red i=spline ;
symbol2 color=red i=spline;
label DECISION=&numnamei.'renshufenbu' n='zongliang' rt_&numnamei.='weiyuelv';
run;
%let i = %eval(&i.+1);
%end;
%mend;
%en();
May someone tell me what's wrong and how to fix it?
data mywork.train is like:
| PassengerId | Survived | Pclass | Name | Sex | Age | SibSp | Parch | Ticket | Fare | Cabin | Embarked |
| 1 | 0 | 3 | Braund, Mr. Owen Harris | male | 22 | 1 | 0 | A/5 21171 | 7.25 | S | |
| 2 | 1 | 1 | Cumings, Mrs. John Bradley (Florence Briggs Thayer) | female | 38 | 1 | 0 | PC 17599 | 71.2833 | C85 | C |
| 3 | 1 | 3 | Heikkinen, Miss. Laina | female | 26 | 0 | 0 | STON/O2. 3101282 | 7.925 | S | |
| 4 | 1 | 1 | Futrelle, Mrs. Jacques Heath (Lily May Peel) | female | 35 | 1 | 0 | 113803 | 53.1 | C123 | S |
| 5 | 0 | 3 | Allen, Mr. William Henry | male | 35 | 0 | 0 | 373450 | 8.05 | S | |
| 6 | 0 | 3 | Moran, Mr. James | male | 0 | 0 | 330877 | 8.4583 | Q | ||
| 7 | 0 | 1 | McCarthy, Mr. Timothy J | male | 54 | 0 | 0 | 17463 | 51.8625 | E46 | S |
| 8 | 0 | 3 | Palsson, Master. Gosta Leonard | male | 2 | 3 | 1 | 349909 | 21.075 | S | |
| 9 | 1 | 3 | Johnson, Mrs. Oscar W (Elisabeth Vilhelmina Berg) | female | 27 | 0 | 2 | 347742 | 11.1333 | S | |
| 10 | 1 | 2 | Nasser, Mrs. Nicholas (Adele Achem) | female | 14 | 1 | 0 | 237736 | 30.0708 | C | |
| 11 | 1 | 3 | Sandstrom, Miss. Marguerite Rut | female | 4 | 1 | 1 | PP 9549 | 16.7 | G6 | S |
| 12 | 1 | 1 | Bonnell, Miss. Elizabeth | female | 58 | 0 | 0 | 113783 | 26.55 | C103 | S |
output out=datasetname;
Just like in proc means, proc summary, proc reg and many other procedures.
you skipped the OUT part.
Your output statement doesn't look right, see http://support.sas.com/documentation/cdl/en/stathpug/66410/HTML/default/viewer.htm#stathpug_hpsplit_...
Get your code to work outside of the macro before you start to make it dynamic.
output out=datasetname;
Just like in proc means, proc summary, proc reg and many other procedures.
you skipped the OUT part.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.