At SAS Global Forum last week, a customer approached me with a very specific request. The conversation went something like this:
Customer: My client demands a bar chart that uses a bar for one response, and a symbol for other responses, all on the same chart. We know it's possible to do with the GCHART procedure, but we don't want to have to use the fancy annotation code.
Me: Great! SAS has the GBARLINE procedure (Bar-Line chart in SAS Enterprise Guide) that supports something like that.
Customer: But in addition to the bar, we need multiple symbol measures.
Me: Ah, I see. In our current release GBARLINE supports just one symbol measure (line), but -- good news -- in SAS 9.2 it actually does support multiple lines.
Customer: Right, but the client wants the bars to be horizontal. GBARLINE supports just vertical bars.
The customer thought he had me stumped, but then I pulled the new SGPLOT procedure out of my bag of tricks.
In a few minutes I had adapted one of the examples from the SAS Online Documentation to show how this could be done. I used the HBAR statement to create the horizontal bar, and I used the HLINE statement (2 of them) to create "lines" with symbol markers. I hid the lines by assigning them a "thickness" of 0.
Here is the program I came up with:
proc sgplot data=sashelp.stocks (where=(date >= "01jan2000"d and date <= "01jan2001"d and stock = "IBM")); hbar date / response=volume legendlabel="Volume"; hline date / response=close x2axis markers markerattrs=(size=12) lineattrs=(thickness=0) legendlabel="Close"; hline date / response=open x2axis markers markerattrs=(size=12) lineattrs=(thickness=0) legendlabel="Open"; x2axis label="Open/Close value"; xaxis label="Trade volume"; run;
And here is the result:
The graph team in R&D tells me that I could have achieved something similar with the DOT statement instead of my little trick to hide the line with a zero thickness.
One of the things that I love about the SGPLOT procedure is that all of the appearance attributes are either in the ODS style or in the procedure block itself -- no need to fuss with the global GOPTIONS like AXIS or LEGEND to get the graph looking like you want it. For more information about this and other statistical graphs, check out this SAS Global Forum paper.