11-23-2016 08:53 PM
I want to add a data table to the bottom of each chart generated using the by statement in proc sgplot.
I have found code to add a table to the bottom of a single chart at: http://support.sas.com/kb/49/697.html
(Sample 49697: Add a table beneath a graph with the Graph Template Language (GTL)).
I would like to replicate this to add a table to the bottom of each chart generated using, for example:
proc sgplot data=sashelp.shoes; by region; vbar subsidiary /response=sales ; run;
Note I like the formatting in the following code better - not that in sample 49697
Any help will be appreciated ... I haven't yet used the Graph Template Language.
11-24-2016 10:04 AM
Well, if I need to loop over a by group and do various then I do this. I create a dataset with all the unique values. Then I use that dataset to generate the statements. I update the code given on that SAS page to show what I mean (the sql and data _null_ at the end). The generate a title and sgrender for each unique region:
proc template; define statgraph barblock; begingraph; entrytitle 'Total Sales Across Regions'; layout lattice / rowweights=(.65 .35); layout overlay; barchart x=region y=sales / group=region barlabel=true dataskin=gloss; endlayout; layout overlay / xaxisopts=(type=discrete label='Number of Stores per Region' display=(label)) walldisplay=none; blockplot x=region block=stores / class=product display=(outline values label) repeatedvalues=true; endlayout; endlayout; endgraph; end; run; proc sort data=sashelp.shoes out=new; by region product; run; proc means data=new noprint; where region in('Africa' 'Asia' 'Canada' 'Pacific' 'United States'); id sales; by region product; var stores; output out=shoes sum=; run; proc sql; create table LOOP as select distinct REGION from NEW; quit; data _null_; set loop; call execute('title "By group is '||strip(region)||'";'); call execute('proc sgrender data=shoes template=barblock; where region="'||strip(region)||'"; run;'); run;
11-25-2016 01:47 PM - edited 11-25-2016 01:56 PM
With SAS 9,4, you can use the XAXISTABLE statement to display the table of data. See code below:
proc sgplot data=sashelp.shoes; by region; vbar subsidiary /response=sales ; xaxistable sales; run;
If you want the bar chart summarized for each subsidiary, but want the data table to show the sales by product, you will need to use the new VBARBASIC with SAS 9.40M3 as shown below.. This is due to the mismatch between VBAR (no group) and XAXISTABLE options.
ods graphics / reset width=6in height=3in imagename='Shoes'; proc sgplot data=sashelp.shoes; by region; vbarbasic subsidiary /response=sales ; xaxistable sales / x=subsidiary class=product; run;
XAXISTABLE has many options. See examples in Graphically Speaking Blog, or SAS documentation.