Operations Research topics: SAS/OR,
SAS Optimization, and SAS Simulation Studio

Drawing a decision tree from HPSPLIT

Accepted Solution Solved
Reply
Respected Advisor
Posts: 4,745
Accepted Solution

Drawing a decision tree from HPSPLIT

Hello, I am looking for example code showing how to create a graphical representation of a decision tree produced with HPSPLIT. I've obtained a graph with proc tree where I put all information in the leaves but I would prefer the layout provided by proc netdraw or proc dtree.

PG

Accepted Solutions
Solution
‎11-02-2015 05:53 PM
Trusted Advisor
Posts: 1,301

Re: Drawing a decision tree from HPSPLIT

[ Edited ]
proc hpsplit data=sashelp.cars;
target origin / level=nominal;
input msrp cylinders length wheelbase mpg_city mpg_highway invoice weight horsepower / level=interval;
input enginesize / level=ordinal;
input drivetrain type / level=nominal;
output nodestats=nstat;
run;

proc sql;
create view treedata as
select a.parent as activity, a.id as node, b.splitvar, b.predictedvalue
from nstat a, nstat b
where a.parent=b.id
union
select c.id as activity, . as node, c.splitvar, c.predictedvalue
from nstat c;
quit;

data treedata1;
set treedata;
select(predictedvalue);
when ('ASIA') _pattern=1;
when ('EUROPE') _pattern=2;
otherwise _pattern=3;
end;
run;

pattern1  c=green; pattern2 v=s c=red;  pattern3 v=s c=blue; 
footnote   c=green   'Asia  '  c=red     'Europe '    c=blue    'USA'; 
proc netdraw data=treedata1 graphics; 
     actnet /activity=activity successor=NODE  id=(splitvar) tree compress rotate rotatetext arrowhead=0 htext=5; 
run;
footnote ' ';

 

Starting in EM14.1, I beleive, PROC HPSPLIT will produce it's own plots

View solution in original post


All Replies
Solution
‎11-02-2015 05:53 PM
Trusted Advisor
Posts: 1,301

Re: Drawing a decision tree from HPSPLIT

[ Edited ]
proc hpsplit data=sashelp.cars;
target origin / level=nominal;
input msrp cylinders length wheelbase mpg_city mpg_highway invoice weight horsepower / level=interval;
input enginesize / level=ordinal;
input drivetrain type / level=nominal;
output nodestats=nstat;
run;

proc sql;
create view treedata as
select a.parent as activity, a.id as node, b.splitvar, b.predictedvalue
from nstat a, nstat b
where a.parent=b.id
union
select c.id as activity, . as node, c.splitvar, c.predictedvalue
from nstat c;
quit;

data treedata1;
set treedata;
select(predictedvalue);
when ('ASIA') _pattern=1;
when ('EUROPE') _pattern=2;
otherwise _pattern=3;
end;
run;

pattern1  c=green; pattern2 v=s c=red;  pattern3 v=s c=blue; 
footnote   c=green   'Asia  '  c=red     'Europe '    c=blue    'USA'; 
proc netdraw data=treedata1 graphics; 
     actnet /activity=activity successor=NODE  id=(splitvar) tree compress rotate rotatetext arrowhead=0 htext=5; 
run;
footnote ' ';

 

Starting in EM14.1, I beleive, PROC HPSPLIT will produce it's own plots

Respected Advisor
Posts: 4,745

Re: Drawing a decision tree from HPSPLIT

Thanks Matt! That gives me a very good start.

 

Note: I had to replace act1 by Activity in the last step.

PG
🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 1095 views
  • 0 likes
  • 2 in conversation