BookmarkSubscribeRSS Feed
Quentin
Super User

HI All,

I want to make a chart with what I'm thinking of as a "nested axis".

For example, conisder a barchart of sashelp.shoes with x=product y=sales.

Now suppose I want the x-axis to be nested, so x-axis could be Region*Subsidiary*Product.

And maybe the x-axis would look like (ASCII Art):

-------------------------------------------------------------------------------------------------------------------------------------------------
shoes             socks            shoes        socks          shoes             socks          shoes             socks 
        Boston                               NewYork                        Paris                                  Madrid
                            North America                                                         Europe

Is there a straightforward way to do that?

Looks like a similar approach is:

proc template;
  define statgraph myplot;
    begingraph;
      layout datapanel classvars=(Region Subsidiary) /
        rows=1
        headerlabeldisplay=value
      ;
        layout prototype ;
          barchart x=product y=Sales /stat=mean;
        endlayout;
      endlayout;
    endgraph;
  end;
run;

proc sgrender
  data=sashelp.shoes 
        (where=(Subsidiary IN ("Chicago" "Los Angeles" "Madrid" "Geneva") 
                and product=: "Men"
                )
         )
  template=myplot
;
run;

Wondering if folks would suggest another approach for this sort of grouping / nesting of an x-axis?

Second question: Assuming I stick with the DATAPANEL approach,  is there a way to get the value of the classvars to display on the bottom of each cell, rather than the top? (in 9.3)

Thanks,

--Q. 

BASUG is hosting free webinars Next up: Jane Eslinger presenting PROC REPORT and the ODS EXCEL destination on Mar 27 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
4 REPLIES 4
Jay54
Meteorite | Level 14

If a two-level axis is acceptable, it is easy.  Use the SGPANEL procedure.as shown in the 3rd graph in this blog article:

http://blogs.sas.com/content/graphicallyspeaking/2013/09/07/bar-charts-with-stacked-and-cluster-grou...

Quentin
Super User

Thanks Sanjay,

That blog post is great!

Users were hoping for a three-level axis, so I Iiked that datapanel supports n levels.

But I like your SGPANEL / DATALATTICE approach, it's definitely closer to what we drew on the white board.  I think I can convince them to put the third level of nesting on the /group=.

--Q.

BASUG is hosting free webinars Next up: Jane Eslinger presenting PROC REPORT and the ODS EXCEL destination on Mar 27 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
Quentin
Super User

Ack, I pay the price for over-simplifying my example.

In real life I want to do this with a box plot, not a bar chart.  I tried:

proc template;
  define statgraph myplot3;
    begingraph;
      layout gridded;
        layout datalattice columnvar=region /
          headerlabeldisplay=value
          columnheaders=bottom 
          border=false
        ;
          layout prototype / ;
            boxplot =subsidiary y=sales;    
             endlayout;
        endlayout;
      endlayout;
    endgraph;
  end;
run;

And it throws:

ERROR 823-580: Computed plots and expressions cannot be used in this layout.


Fair enough, the docs say that as well. Boxplot is a no-go for layout prototype.

Then I tried SGPanel and it works:

proc sgpanel
  data=sashelp.shoes 
        (where=(Subsidiary IN ("Chicago" "Los Angeles" "Madrid" "Geneva") 
                and product=: "Men"
                )
         )
;
  panelby Region/ layout=columnlattice novarname noborder colheaderpos=bottom;
  vbox sales/group=product category=subsidiary;
  colaxis display=(nolabel);
  rowaxis grid;
run;

I haven't used SGPANEL.  I had assumed it was generating GTL code behind the scenes, like SGPLOT.  So I thought it wouldn't work with vbox.  But it does work.  Then I thought "Oh, let me see what GTL code SGPANEL is generating", and there is no TMPLOUT= option.

So a few questions:

1. SGPanel isn't generating GTL code???

2. Is there a way I can do what SGPanel is doing, with GTL code?

-- Was thinking even though layout prototype doesn't like box plots, looks like perhaps I could roll my own, using e.g. layout lattice, with one layout overlay block for each box plot

I'm not averse to following the SGPANEL route a bit.  It's just that often I end up doing enough crazy stuff with reference lines and html drill downs that I wind up back in GTL-land.

Thanks,

-Q.

BASUG is hosting free webinars Next up: Jane Eslinger presenting PROC REPORT and the ODS EXCEL destination on Mar 27 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
Jay54
Meteorite | Level 14

If thsi is a custom graph, you can annotate the macro level label under the axis.

The VBAR can be clustered without the stacks.

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
  • 4 replies
  • 1726 views
  • 3 likes
  • 2 in conversation