Resources

Oil Wildcatter's Problem (dtree0)

 /**************************************************************/
 /*          S A S   S A M P L E   L I B R A R Y               */
 /*                                                            */
 /*    NAME: DTREE0                                            */
 /*   TITLE: Oil Wildcatter's Problem (dtree0)                 */
 /* PRODUCT: OR                                                */
 /*  SYSTEM: ALL                                               */
 /*    KEYS: DTREE                                             */
 /*   PROCS: DTREE, PRINT                                      */
 /*    DATA:                                                   */
 /*                                                            */
 /* SUPPORT:                             UPDATE:               */
 /*     REF: Examples from the Getting Started & Details       */
 /*          sections of DTREE chapter                         */
 /*    MISC:                                                   */
 /*                                                            */
 /**************************************************************/

/* -- create the STAGEIN= data set            -- */
data Dtoils1;
format _STNAME_ $12. _STTYPE_ $2. _OUTCOM_ $10.
     _SUCCES_ $12. ;
input _STNAME_ $ _STTYPE_ $ _OUTCOM_ $ _SUCCES_ $ ;
datalines;
Drill       D   Drill       Cost
.           .   Not_Drill   .
Cost        C   Low         Oil_Deposit
.           .   Fair        Oil_Deposit
.           .   High        Oil_Deposit
Oil_Deposit C   Dry         .
.           .   Wet         .
.           .   Soaking     .
;


/* -- create the PROBIN= data set               -- */
data Dtoilp1;
input _EVENT1 $ _PROB1
      _EVENT2 $ _PROB2
      _EVENT3 $ _PROB3 ;
datalines;
Low   0.2   Fair   0.6   High      0.2
Dry   0.5   Wet    0.3   Soaking   0.2
;


/* -- create PAYOFFS= data set                  -- */
data Dtoilu1;
format _STATE1-_STATE3 $12. _VALUE_ dollar12.0;
input _STATE1 $ _STATE2 $ _STATE3 $ ;

/* determine the cost for this scenario */
if _STATE1='Low' then _COST_=150000;
else if _STATE1='Fair' then _COST_=300000;
else _COST_=500000;

/* determine the oil deposit and the          */
/* corresponding net payoff for this scenario */
if _STATE2='Dry' then _PAYOFF_=0;
else if _STATE2='Wet' then _PAYOFF_=700000;
else _PAYOFF_=1200000;

/* calculate the net return for this scenario */
if _STATE3='Not_Drill' then _VALUE_=0;
else _VALUE_=_PAYOFF_-_COST_;

/* drop unneeded variables */
drop _COST_ _PAYOFF_;

datalines;
Low         Dry         Not_Drill
Low         Dry         Drill
Low         Wet         Not_Drill
Low         Wet         Drill
Low         Soaking     Not_Drill
Low         Soaking     Drill
Fair        Dry         Not_Drill
Fair        Dry         Drill
Fair        Wet         Not_Drill
Fair        Wet         Drill
Fair        Soaking     Not_Drill
Fair        Soaking     Drill
High        Dry         Not_Drill
High        Dry         Drill
High        Wet         Not_Drill
High        Wet         Drill
High        Soaking     Not_Drill
High        Soaking     Drill
;


/* -- print the payoff table               -- */

title "Oil Wildcatter's Problem";
title3 "The Payoffs";

proc print data=Dtoilu1;
run;

   /* -- PROC DTREE statements              -- */
title "Oil Wildcatter's Problem";

proc dtree stagein=Dtoils1
           probin=Dtoilp1
           payoffs=Dtoilu1
           nowarning;

   evaluate / summary;

 OPTIONS LINESIZE=100;
 treeplot/ lineprinter;
 OPTIONS LINESIZE=78;

evaluate / criterion=maxce rt=700000 summary;


   vpi Oil_Deposit;

   vpi Cost;

   save;
   move Cost before Drill;
   evaluate;
   recall;
   vpc Cost;
quit;

/* -- create the STAGEIN= data set              -- */
data Dtoils2;
format _STNAME_ $12. _STTYPE_ $2.  _OUTCOM_ $14.
    _SUCCES_ $12. _REWARD_ dollar12.0;
input _STNAME_ & _STTYPE_ & _OUTCOM_ &
    _SUCCES_ & _REWARD_ dollar12.0;
datalines;
Drill        D   Drill           Cost                 .
.            .   Not_Drill       .                    .
Cost         C   Low             Oil_Deposit          .
.            .   Fair            Oil_Deposit          .
.            .   High            Oil_Deposit          .
Oil_Deposit  C   Dry             .                    .
.            .   Wet             .                    .
.            .   Soaking         .                    .
Sounding     D   Noseismic       Drill                .
.            .   Seismic         Structure     -$60,000
Structure    C   No_Struct       Drill                .
.            .   Open_Struct     Drill                .
.            .   Closed_Struct   Drill                .
;


      /* -- create PROBIN= data set                   -- */
   data Dtoilp2;
      format _EVENT1 $10. _EVENT2 $12. _EVENT3 $14. ;
      input _GIVEN_ $ _EVENT1 $ _PROB1
            _EVENT2 $ _PROB2  _EVENT3 $ _PROB3;
      datalines;
   .       Low       0.2 Fair        0.6 High          0.2
   .       Dry       0.5 Wet         0.3 Soaking       0.2
   Dry     No_Struct 0.6 Open_Struct 0.3 Closed_Struct 0.1
   Wet     No_Struct 0.3 Open_Struct 0.4 Closed_Struct 0.3
   Soaking No_Struct 0.1 Open_Struct 0.4 Closed_Struct 0.5
   ;


   /* -- PROC DTREE statements                     -- */
title "Oil Wildcatter's Problem";
proc dtree stagein=Dtoils2
           probin=Dtoilp2
           payoffs=Dtoilu1
           nowarning
           ;

   evaluate;
   summary / target=Sounding;

   summary / target=Drill;

   save;
   modify Seismic reward 0;
   evaluate;
   recall;

quit;




 /* -- create the STAGEIN= data set                -- */
data Dtoils4;
   format _STNAME_ $12. _STTYPE_  $2. _OUTCOM_ $10.
         _SUCCES_ $12.;
   input _STNAME_ $ _STTYPE_ $ _OUTCOM_ $ _SUCCES_ $;
   datalines;
Drill       D   Drill       Cost
.           .   Not_Drill   .
Cost        C   Low         Oil_Deposit
.           .   High        Oil_Deposit
Oil_Deposit C   Dry         .
.           .   Wet         .
;

/* -- TreePlot with FORMCHAR -- */
title " ";
title2 "Decision Tree Showing the Effects of FORMCHAR";

proc dtree stagein=Dtoils4
           nowarning
           ;
   treeplot / formchar(1 2 3 5 8 9 11 13)='|-/*<\+='
              lineprinter display=(LINK);

quit;


data Dtoils3;
   format _STNAME_ $12. _STTYPE_ $2. _OUTCOM_ $10.
         _REWARD_ dollar12.0  _SUCCES_ $12.;
   input _STNAME_ $12. _STTYPE_  $4. _OUTCOM_ $12.
         _REWARD_ dollar12.0  _SUCCES_ $12.;
   datalines;
Drill       D   Drill              .    Cost
.           .   Not_drill          .    .
Cost        C   Low           -$150,000 Oil_deposit
.           .   Fair          -$300,000 Oil_deposit
.           .   High          -$500,000 Oil_deposit
Oil_deposit C   Dry                .    .
.           .   Wet            $700,000 .
.           .   Soaking      $1,200,000 .
;

/* -- create PAYOFFS= data set                    -- */
data Dtoilp3;
   input _EVENT1 $ _PROB1 _EVENT2 $ _PROB2;
   datalines;
Low    0.2   Dry       0.5
Fair   0.6   Wet       0.3
High   0.2   Soaking   0.2
;
/* -- PROC DTREE statements                       -- */
title "Oil Wildcatter's Problem";
proc dtree stagein=Dtoils3
           probin=Dtoilp3
           nowarning;
   evaluate / summary;

  move Cost before Drill;
  evaluate / summary;

quit;

  /* -- clear up                                    -- */
title ;