Hi,
I am having trouble implementing SEGLABELS for each segment and total above the bars in a stacked column chart. Could I get some assistance on how to implement this inside my code? The code prints 2 charts as you will see, the latter chart is the main chart in-use once the previous code completes it's final sort. Thank you for your time.
Code:
/* Set the graphics environment */
goptions reset=all cback=white border htitle=12pt htext=12pt;
/* Calculate totals for Closed_Date and Close_Reason */
proc means data=work.dailyclosures noprint;
by Closed_Date;
class Close_Reason;
var Closures;
output out=closure1(where=(_type_=1)) sum=;
run;
/* Within Closed_Date (the midpoint) make highest sales come first */
proc sort data=closure1;
by Closed_Date descending Closures Close_Reason;
run;
/* The code below generates the default results. */
title1 'MTD Closures October 19, 2018';
legend1 label=('Close Reason') ;
pattern1 color=CX66A5A0 value=l3;
pattern2 color=CX7C95CA value=solid;
pattern3 color=CX94BDE1 value=solid;
pattern4 color=CXDE7E6F value=solid;
pattern5 color=CXA9865B value=r3;
pattern6 color=CXBABC5C value=solid;
pattern7 color=CXB689CD value=solid;
pattern8 color=CXCD7BA1 value=solid;
axis1 label=none split='/' value=(height=1)
value=(height=.7 "1" "2" "3" "4" "5" "6" "7" "8" "9" "10" "11" "12" "13" "14" "15" "16" "17" "18" "19");
axis2 minor=(number=3) label=(angle=90 height=1 "Total Closures")
value=(height=1 "0" "10" "20" "30" "40" "50" "60" "70" "80" "90" "100");
proc gchart data=closure1;
vbar Closed_Date / sumvar=Closures subgroup=Close_Reason legend=legend1
maxis=axis1 raxis=axis2 space=8
type = sum midpoints=('01oct2018'd to '19oct2018'd);
run;
quit;
/* The code below reorders the subgroups. */
goptions reset=all cback=white border htitle=12pt htext=12pt;
/* Create a RANK variable. This will be used as the SUMVAR= */
/* variable to ensure that the Close_Reason with the highest sales */
/* is drawn at the bottom of each bar. */
/* Assign a color and pattern value for each Close_Reason. */
/* Assign color and pattern values to a macro variable. Each */
/* observation creates one macro variable. This ensures that */
/* each Close_Reason has the same color and pattern across midpoints */
/* even though the RANK value is different for each Close_Reason. */
data closure2;
set closure1 end=eof;
by Closed_Date descending Closures Close_Reason;
length color $20 value $5;
Closed_Date = tranwrd(strip(Closed_Date)," ","/");
rank + 1;
select;
when (Close_Reason="Test") do;
color="CX66A5A0";
value="L3";
end;
when (Close_Reason="Test1") do;
color="CX7C95CA";
value="solid";
end;
when (Close_Reason="Test2") do;
color="CX94BDE1";
value="solid";
end;
when (Close_Reason="Test3") do;
color="CX9B58A6";
value="R3";
end;
when (Close_Reason="Test4") do;
color="CXBDB2BF";
value="solid";
end;
otherwise;
end;
if eof then call symput('tot',trim(left(put(_n_,8.))));
call symput('pattern'||trim(left(put(_n_,8.))),'color=' || color || ' value=' || value ||';');
run;
/* Define and execute the macro to create the PATTERN statements */
%macro pattern;
%do j=1 %to &tot;
pattern&j &&pattern&j;
%end;
%mend pattern;
%pattern;
/* Keep one observation for each Close_Reason */
proc sort data=closure2 out=unqshoes nodupkey;
by Close_Reason;
run;
/* Create macro variables to use in the legend. */
/* ORD contains the list of ranks that will be */
/* used in the ORDER= option. */
/* VAL contains the list of Close_Reason names that */
/* will be used in the VALUE= option. */
data _null_;
set unqshoes end=eof;
length ord val $600;
retain ord val ' ';
ord = trim(left(ord)) || ' ' || trim(left(put(rank,12.)));
val = trim(left(val)) || ' "' || Close_Reason || '"';
if eof then do;
call symput('ord', ord);
call symput('val', val);
end;
run;
title1 "MTD Closures October 19, 2018";
legend1 label=('Close Reason') order=(&ord) value=(j=l &val);
axis1 label=none split='/' value=(height=1)
value=(height=.7 "1" "2" "3" "4" "5" "6" "7" "8" "9" "10" "11" "12" "13" "14" "15" "16" "17" "18" "19");
;
axis2 minor=(number=3) label=(angle=90 height=1.25 "Total Closures")
value=(height=1 "0" "10" "20" "30" "40" "50" "60" "70" "80" "90" "100");
proc gchart data=closure2;
vbar Closed_Date / sumvar=Closures subgroup=rank legend=legend1
maxis=axis1 raxis=axis2 space=.5
type = sum midpoints=('01oct2018'd to '19oct2018'd);
run;
quit;