Data visualization with SAS programming

How to put error bars in vertical bars when using subgroup as an option

Reply
Contributor sfo
Contributor
Posts: 66

How to put error bars in vertical bars when using subgroup as an option

Hello,

I need to put top error bars on my vertical bar charts. I am using porc gchart and have to use Subgroup option. I am getting the following warning when I use errorbar=top option "WARNING: Error bars are not supported when SUBGROUP= is specified.".

Can anyone please help me?

Thanks,

SAS Super FREQ
Posts: 889

How to put error bars in vertical bars when using subgroup as an option

To render this graph, you would need to compute the standard error for the entire bar and overlay the error bars as a separate plot. I can show you how to do this using the Graph Template Language (GTL) if you have SAS 9.2 or greater. What version of SAS do you have?

Contributor sfo
Contributor
Posts: 66

How to put error bars in vertical bars when using subgroup as an option

Thanks for the reply. I use 9.2, if possible can you give me the idea how to use GTL?

Contributor sfo
Contributor
Posts: 66

Re: How to put error bars in vertical bars when using subgroup as an option

Hi Dan,

I will really appreciate if you can give me an example of how to create standard error bars on bar graphs with subgroup as an option using GTL when working in SAS 9.2?

Thanks

SAS Super FREQ
Posts: 889

Re: How to put error bars in vertical bars when using subgroup as an option

Sorry, I forgot to get with you on this. I've put together a little example below. The tricky part is not the graph template -- it's getting the data correct to draw the error bars in the correct location. In the example below, the stderr is computed in PROC SUMMARY, but is later modified to position the error bar correctly at the top of the bar. Let me know if you have any questions about it.

Thanks!
Dan

/* First, all data used for the overlay must be summarized */
proc summary data=sashelp.class nway;
class age;
var height;
output out=limits sum=limitsum stderr=stderr;
run;

proc summary data=sashelp.class nway;
class age sex;
var height;
output out=subgroups sum=barsum;
run;

data limits2;
rename age=age2;
set limits (keep=age stderr limitsum);
ustderror = limitsum + stderr;
lstderror = limitsum - stderr;
run;

data merged;
merge subgroups limits2;
run;


/* The graph template */
proc template;
define statgraph barlimits;
begingraph;
layout overlay;
   barchartparm x=age y=barsum / group=sex primary=true;
   scatterplot x=age2 y=limitsum / yerrorupper=ustderror yerrorlower=lstderror markerattrs=(size=0);
endlayout;
endgraph;
end;
run;

proc sgrender data=merged template=barlimits; run;

Contributor sfo
Contributor
Posts: 66

How to put error bars in vertical bars when using subgroup as an option

Thank you Dan. The code you sent me worked.

Contributor sfo
Contributor
Posts: 66

Re: How to put error bars in vertical bars when using subgroup as an option

Dear Dan,

Thanks a lot for answering my query regarding plotting the error bars in vertical bars.

Can you please help me if there is a way I can specify colors for each bar? I did some Google research but I can't find the solution to it. Does goptions work here too?

Thanks a lot for your help.

SAS Super FREQ
Posts: 3,406

Re: How to put error bars in vertical bars when using subgroup as an option

A more general question is "is a bar chart with a confidence interval a good way to display these data." A discussion of this question is available at

http://blogs.sas.com/content/iml/2011/10/07/creating-bar-charts-with-confidence-intervals/

Ask a Question
Discussion stats
  • 7 replies
  • 789 views
  • 3 likes
  • 3 in conversation