BookmarkSubscribeRSS Feed
Quentin
PROC Star

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. 

Check out the Boston Area SAS Users Group (BASUG) video archives: https://www.basug.org/videos.
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
PROC Star

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.

Check out the Boston Area SAS Users Group (BASUG) video archives: https://www.basug.org/videos.
Quentin
PROC Star

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.

Check out the Boston Area SAS Users Group (BASUG) video archives: https://www.basug.org/videos.
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

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1604 views
  • 3 likes
  • 2 in conversation