Hi, I am creating a stack bar plot using PROC TEMPLATE and SGRENDER. However, I noticed that the legend values are in the alphabetical order, while I would like them to be in a the 'natural" order. I.e., White, Black, Other not White, Other, Black OR Black, Other, White. Basically, is there a way to control the values of the legend? I tried using numeric values associated with my race group, but then I don't want to display 1,2,3 in the legend. When I format the 1,2,3 to represent White, Black, Other...the legend values are once again alphabetized. Thank you! data clusterbarstack; length cluster $9 stack $5; input year cluster $ stack $ pct num_stack; label pct="Patients (%)"; datalines; 2010 A White 90 1 2010 A Black 8 2 2010 A Other 2 3 2010 B White 85 1 2010 B Black 15 2 2010 B Other 0 3 2010 C White 50 1 2010 C Black 45 2 2010 C Other 5 3 2011 A White 92 1 2011 A Black 7 2 2011 A Other 1 3 2011 B White 85 1 2011 B Black 12 2 2011 B Other 3 3 2011 C White 51 1 2011 C Black 40 2 2011 C Other 9 3 ; run; proc template; define statgraph delete; DYNAMIC _WIDTH _HEIGHT _XAXIS _YAXIS _CLUSTER _STACK _YSTART _YEND _YINC _XSTART _XEND _XINC _YFMT _XFMT _YLO _YHI _XLO _XHI; begingraph / designwidth=_WIDTH designheight=_HEIGHT; layout gridded; layout datalattice columnvar=_XAXIS / headerlabeldisplay=value columnheaders=bottom border=false columngutter=14 rowaxisopts=(offsetmin=0 offsetmax=0 display=(ticks tickvalues label) displaysecondary=none) row2axisopts=(offsetmin=0 offsetmax=0 display=none) columnaxisopts=(display=(line ticks tickvalues)); layout prototype / cycleattrs=true walldisplay=none; barchart x=_CLUSTER y=_YAXIS / name="leg" group=_STACK GROUPORDER = deSCENDING ; endlayout; endlayout; discretelegend "leg" /location=outside /*VALIGN = BOTTOM;**/ across=1 halign=right valign=top opaque=true border=false sortorder=ASCENDINGFORMATTED ; endlayout; endgraph; end; run; proc sgrender data=clusterbarstack template=delete; DYNAMIC _WIDTH="2400px" _HEIGHT="1200px" _XAXIS="year" _YAXIS="pct" _CLUSTER="cluster" /* _STACK="stack";*/ _STACK="num_stack"; run; proc format; value race 1 = "White" 2 = "Black" 3 = "Other"; run; *apply format; proc sgrender data=clusterbarstack template=delete; DYNAMIC _WIDTH="2400px" _HEIGHT="1200px" _XAXIS="year" _YAXIS="pct" _CLUSTER="cluster" /* _STACK="stack";*/ _STACK="num_stack"; format num_stack race.; run;
... View more