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

Hi, I am creating a horizontal stacked bar chart with percentage on the x-axis and supply item on the y-axis where each segment of the bar shows on-hand supply of that item (length of time before factory runs out of item, 4 groups = 0 days, 1 day, 2 days, 3 days). Reporting of supply data is optional, so different supply items may have different sample sizes. I would like to include the sample size for the number of factories represented in each full bar (sum the number of factories across the 4 possible segments of each bar). Because this is a stacked bar chart with 4 groups included in each bar, the datalabel option displays 4 columns summarizing sample size for each. I tried to force SAS to include sample size for just one of the 4 segments by setting 3 values to missing but missing values are still displayed (see photo). Based on the photo shown, I would like to keep the "0 days" column (and will rename "Number of Factories"). Is there a way to 1) suppress datalabel columns where values are "." or 2) apply a where statement to datalabel (such as, datalabel=num_factories(where supply_length='0 days') or 3) create and display another summary variable that sums supply_count across the 4 segments (supply_count/num_factories=percent). The code used to create the example chart is displayed here:

 

 

proc sgplot data=test dattrmap=attrmap;

hbar supply / response=percent group=supply_length groupdisplay=stack attrid=myid datalabel=fac_count datalabelpos=right nooutline;

keylegend /title='On-hand supply availability';

xaxis grid values=(0 to 100 by 10) label="Percentage";

yaxis discreteorder=data label="Supply Item";

run;

 

Supply availability stacked bar chart example.jpg

 

Dataset example stacked bar.jpg

  

Thank you!

 

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

Yes. Read the documentation for the KEYLEGEND statement. Use the NAME= option to specify the statements that you want to appear in the legend. You might also need to use the NOAUTOLEGEND option:

 

proc sgplot NOAUTOLEGEND ...;
hbar supply / name="bar" ...;

keylegend "bar" / ...;p
run;

View solution in original post

3 REPLIES 3
Rick_SAS
SAS Super FREQ

I suggest you use the YAXISTABLE statement to display the sample size and any other statistics.

Here's an example.

Clary_CO
Calcite | Level 5

Thank you! Just tried the yaxistable statement with nomissingchar option and get the N I wanted (thanks!), however, the legend disappears and I get the error message "DISCRETELEGEND statement with DISPLAYCLIPPED=FALSE is getting clipped. The legend will not be drawn." I tried adding the discretelegend option and now have 2 legends displayed. Do you know how to maintain the original legend on bottom once the yaxistable statement is added?

 

Legend.jpg

 

Rick_SAS
SAS Super FREQ

Yes. Read the documentation for the KEYLEGEND statement. Use the NAME= option to specify the statements that you want to appear in the legend. You might also need to use the NOAUTOLEGEND option:

 

proc sgplot NOAUTOLEGEND ...;
hbar supply / name="bar" ...;

keylegend "bar" / ...;p
run;

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 2841 views
  • 0 likes
  • 2 in conversation