Somebody wants standard error bars added to a histogram. I am hoping just to modify my PROC SGPLOT to add.
I thought it would be simple -- just add yerrorlower= yerrorupper = after the slash on the VBAR statement. But apparently VBAR doesn't like those.
Then I tried a separate SCATTER statement with the error bars. But again, I got this red error message:
ERROR: Attempting to overlay incompatible plot or chart types.
So, can I do a histogram with these bars? I see pictures of them, so I know the idea isn't insane:
Any ideas? Thank you. Here is my code (with the failed SCATTER statement left in. prior to that I tried yerrorlower= yerrowupper= after the slash on the VBAR statement).
proc sgplot data = adcv4 noautolegend;
where paramcd = 'LVMASSIX';
vbar tx / group = tx
datalabel = txtext
datalabelpos=top
datalabelattrs = (color=black family="courier new" size=11 weight=bold)
filltype=solid outlineattrs=(color='black') response=meanchg;
scatter x=tx y=meanchg / yerrorlower=lower
yerrorupper=upper;
styleattrs datacolors=(viypk vligb);
xaxis label = ' '
display = (noticks novalues)
offsetmin = .3 offsetmax = .3;
yaxis label = 'Mean Percent'
labelattrs = (family = "courier new" size = 10 pt color = black weight = bold)
values = (-2 to 8 by 2);
run;
See the section "Bar charts for pre-summarized data" in the article "Creating bar charts with confidence intervals."
See also the end of the article, which suggests using a dot plot or scatter plot instead.
You'll want to use the VBARPARM statement instead of the VBAR statement to put your own limit variables on the bar chart. The VBAR statement can display only the limits it calculates (CLM, STDERR, STDDEV), whereas you can specify your own custom LIMITUPPER/LIMITLOWER with the VBARPARM statement.
Because of internal reasons some plots are not compatible with others. If you want to overlay a Scatter plot on vertical bar chart then use VBARBASIC instead of Vbar.
See the section "Bar charts for pre-summarized data" in the article "Creating bar charts with confidence intervals."
See also the end of the article, which suggests using a dot plot or scatter plot instead.
Hi Rick,
I had a lot of success with this just now. I'm getting my SE bars, and still have the DATALABEL at the top. (I just need to find the syntax to set the error bars black in this situation; it seems different than other situations in which I've done that).
Unfortunately, without the "GROUP=" , I am no longer getting the two different colors for the two groups. But if I add "GROUP =", the error bars go away. Ugh, I need to do something else for a living. Thank you...
(current code)
proc sgplot data = /*adcv4*/ adcv0 noautolegend;
where paramcd = 'LVMASSIX';
vbar tx / response = pchg stat = mean limitstat = stderr
datalabel = txtext datalabelpos=top
datalabelattrs = (color=black family="courier new" size=11 weight=bold)
filltype=solid outlineattrs=(color='black');
styleattrs datacolors = (viypk vligb);
xaxis label = ' '
display = (noticks novalues)
offsetmin = .3 offsetmax = .3;
yaxis label = 'Mean Percent'
labelattrs = (family = "courier new" size = 10 pt color = black weight = bold)
values = (-4 to 12 by 2);
run;
(current output)
Add GROUPDISPLAY=CLUSTER to the VBAR statement to get your error bars back.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.