title: SAS "Double" Waterfall sgplot
body: <p>I have a data set that looks like this:</p>
  
  <pre><code>data have;
      input category $ type $ percent order;
  datalines;
  X Full 1 1
  X B -.04 .
  X A -.02 .
  X E 0 .
  X D .03 .
  X C .01 .
  ;
  run;
  </code></pre>
  
  <p>I want to create a waterfall showing what is "Leftover" after the modifications A-E.  The code below does this successfully. </p>
  
  <p>I have two questions:</p>
  
  <ol>
  <li>I wish to further waterfall from the "Leftover" bar.  Suppose another modification, F, has a value of .60.  I wish to subtract this value from "Leftover" to get "Leftover 2" (see picture <a href="http://tinypic.com/r/mb4tat/8" rel="nofollow">http://tinypic.com/r/mb4tat/8</a> ).  I don't know if this is possible, but I really would like both Leftovers displayed.  </li>
  <li>The code below is messy.  I had to create some workarounds to get the bars to show up in the order I wanted.  Is there a better way to dictate these values?</li>
  </ol>
  
  <p>Thanks!</p>
  
  <pre><code>proc sort data=have(where=(percent&lt;0)) 
      out=neg;
      by percent;
  run;
  
  data neg;
      set neg;
      order=_N_+1;
  run;
  
  proc sql noprint;
      select max(order) into :max_order from neg;
  quit;
  
  proc sort data=have(where=(percent&gt;0 and type not in ("Full"))) 
      out=pos;
      by descending percent;
  run;
  
  data pos;
      set pos;
      order=_N_+&amp;max_order.;
  run;
  
  data x_have;
      set have(where=(type="Full")) neg pos;
  run;
  
  proc sort data=x_have;
  by order;
  run;
  
  proc sgplot data=have(where=(percent ne 0)) noautolegend;
  waterfall category=type response=percent  / colorgroup=type dataskin=sheen datalabel name='a'
  finalbartickvalue='Leftover';
  ;
  xaxis display=(nolabel);
  yaxis grid display=(nolabel) offsetmin=0;
  run;
  </code></pre>