BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mduarte
Quartz | Level 8

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)).

 

Capture.PNG

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.

 

Thanks,

Marie

1 ACCEPTED SOLUTION

Accepted Solutions
Jay54
Meteorite | Level 14

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;

Shoes.png

 

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;

 

ShoesClass.png

XAXISTABLE has many options.  See examples in Graphically Speaking Blog, or SAS documentation.

 

 

 

 

 

 

View solution in original post

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;
Jay54
Meteorite | Level 14

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;

Shoes.png

 

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;

 

ShoesClass.png

XAXISTABLE has many options.  See examples in Graphically Speaking Blog, or SAS documentation.

 

 

 

 

 

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 6461 views
  • 3 likes
  • 3 in conversation