I have a data set that looks like this:
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;
I want to create a waterfall showing what is "Leftover" after the modifications A-E. The code below does this successfully.
I have two questions:
- 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 http://tinypic.com/r/mb4tat/8 ). I don't know if this is possible, but I really would like both Leftovers displayed.
- 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?
Thanks!
proc sort data=have(where=(percent<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>0 and type not in ("Full")))
out=pos;
by descending percent;
run;
data pos;
set pos;
order=_N_+&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;