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

I have a small data set containing roughly 30 cases which have variables for ID (alphanumeric), size ("Large", "Extra Large"), a variable containing the percent passed using one inspection type (call it "Contractor_Passed") and another containing the percent passed using another type ("Public_Passed"). I want a horizontal bar chart with all the agencies on the y axis (showing the ID variable), each having two bars (one under the other): one for each score type.  Basically, I'm comparing the percent passed of each type of inspection for each agency.  

I've tried looking online, but all of the gcharts with subgroups I've found have grouping based one one dichotomous categorical variable (e.g. gender) with single split bars.  Can Gchart make over-under bars with grouping based on two numeric variables, which I am comparing?  If necessary, I can make one for each size category and then use GREPLAY to put them side by side. 

1 ACCEPTED SOLUTION

Accepted Solutions
DanH_sas
SAS Super FREQ

Try this example, and see if it is what you want:

proc sgplot data=sashelp.class;

hbar age / response=height stat=mean barwidth=0.4 discreteoffset=-0.2 x2axis;

hbar age / response=weight stat=mean barwidth=0.4 discreteoffset=0.2;

run;

View solution in original post

6 REPLIES 6
DanH_sas
SAS Super FREQ

Try this example, and see if it is what you want:

proc sgplot data=sashelp.class;

hbar age / response=height stat=mean barwidth=0.4 discreteoffset=-0.2 x2axis;

hbar age / response=weight stat=mean barwidth=0.4 discreteoffset=0.2;

run;

DanH_sas
SAS Super FREQ

I just saw that both of your responses are percentages, so you might want to drop the "x2axis" option from the first HBAR statement.

WGE914
Calcite | Level 5

I think I found a way to combine the two graphs I have using SGPANEL, but I cannot get the layout the way I want it.   When I split the panels by size (2 categories) I see all the cases along wht x axis for both categories, leaving a lot of empty space in the panels.  My data set is structured so that each record is ONE of the TWO categories I am splitting the panels by.  How do I remove the empty records from the panels so that each panel only includes the applicable records instead of all?    Here is my working code:

proc sgpanel data=DATA_FINAL;

  panelby size  ;

  rowaxis label="Percent Passed";

  colaxis discreteorder=data label = 'Agency';

vbar ID / response=_Passed_by_c stat=mean barwidth=0.4  discreteoffset=0.5  ;

vbar ID / response=_Passed_by_P stat=mean barwidth=0.8  discreteoffset=0.5 transparency=.4 ;

run;

quit;

Once I get this fixed, I can work on the bar widths and spacing.

DanH_sas
SAS Super FREQ

On the PANELBY statement, specify:

panelby size / uniscale=row layout=columnlattice;

Also, I'm not sure of your intent, by having both DISCRETEOFFSETs set to 0.5 will still make the bars be on top of one another. Did you mean to drop the minus from one of the statements?

Hope this helps!

Dan

WGE914
Calcite | Level 5

I prefer to have the bars completely overlapped; I find it much easier to read when the differences between the two are so great.  I also increased the width of the bar corresponding to the 'base' measure so that the reader can differentiate the measures in the lower portion.

DanH_sas
SAS Super FREQ

If you like the overlap, you might like this approach better:

vbar ID / response=_Passed_by_c stat=mean transparency=.4

vbar ID / response=_Passed_by_P stat=mean barwidth=0.5  transparency=.4 ; 

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