Improving http://support.sas.com/kb/41/603.html Two problems, I lost the tooltip when sorting and the processing is a little high when sorting. Any suggestions on how this could be more efficient in 9.2? /*proc print data=sashelp.shoes double; var region sales product; run;*/ proc sql; CREATE TABLE shoes( region varchar(50), sales int, product varchar(50), product_id int ); INSERT INTO shoes (region, sales, product, product_id) VALUES ('1', 10, 'A', 3); INSERT INTO shoes (region, sales, product, product_id) VALUES ('1', 200, 'B', 2); INSERT INTO shoes (region, sales, product, product_id) VALUES ('1', 60, 'B', 2); INSERT INTO shoes (region, sales, product, product_id) VALUES ('1', 20, 'D', 1); INSERT INTO shoes (region, sales, product, product_id) VALUES ('1', 20, 'D', 1); INSERT INTO shoes (region, sales, product, product_id) VALUES ('1', 20, 'D', 1); INSERT INTO shoes (region, sales, product, product_id) VALUES ('1', 20, 'D', 1); INSERT INTO shoes (region, sales, product, product_id) VALUES ('1', 20, 'D', 1); INSERT INTO shoes (region, sales, product, product_id) VALUES ('1', 20, 'D', 1); INSERT INTO shoes (region, sales, product, product_id) VALUES ('2', 20, 'B', 2); INSERT INTO shoes (region, sales, product, product_id) VALUES ('2', 200, 'B', 2); INSERT INTO shoes (region, sales, product, product_id) VALUES ('2', 20, 'D', 1); quit; proc sort data=shoes; by region product_id; run; /* Calculate totals for region and product */ proc summary data=shoes noprint; by region product_id; class product; var sales; output out=shoes1(where=(_type_=1)) sum=; run; /* Within region (the midpoint) make highest sales come first */ proc sort data=shoes1; by region product_id sales; run; /* The code below generates the default results. */ title1 'Default Graph of Sales Totals'; legend1 label=('Product Category') ; 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; proc gchart data=shoes1; vbar region / sumvar=sales subgroup=product legend=legend1 maxis=axis1 raxis=axis2 space=.5; run; quit; /* The code below reorders the subgroups. */ goptions reset=all cback=white border htitle=12pt htext=10pt; /* Create a RANK variable. This will be used as the SUMVAR= */ /* variable to ensure that the product with the highest sales */ /* is drawn at the bottom of each bar. */ /* Assign a color and pattern value for each product. */ /* Assign color and pattern values to a macro variable. Each */ /* observation creates one macro variable. This ensures that */ /* each product has the same color and pattern across midpoints */ /* even though the RANK value is different for each product. */ data shoes2; set shoes1 end=eof; by region product_id sales; length color $20 value $5; region = tranwrd(strip(region)," ","/"); rank + 1; select; when (product='D') do; color="CX66A5A0"; value="L3"; end; when (product='B') do; color="CXB689CD"; value="solid"; end; when (product='A') do; color="CXCD7BA1"; 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 product */ proc sort data=shoes2 out=unqshoes nodupkey; by product_id; 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 product names that */ /* will be used in the VALUE= option. */ data _null_; set unqshoes end=eof; length ord val $200; retain ord val ' '; ord = trim(left(ord)) || ' ' || trim(left(put(rank,8.))); val = trim(left(val)) || ' "' || product || '"'; if eof then do; call symput('ord', ord); call symput('val', val); end; run; title1 "Reorder Subgroups Based on Product Id"; legend1 label=('Product Category') order=(&ord) value=(j=l &val); proc gchart data=shoes2; vbar region / sumvar=sales subgroup=rank legend=legend1 type=sum space=.5; run; quit;
... View more