- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I was trying to create a barchart with error bars, my x-axis= month, y-axis=CO2flux.. Here is my code;
proc sort data=mydata.butner_new1 out=btnret;
by spacing;
run;
proc means data=btnret nway mean clm noprint;
by spacing;
class month;
var CO2flux;
output out=new mean= lclm= uclm= / autoname;
run;
proc template;
define statgraph barchart;
begingraph;
entrytitle 'Bar Chart with Error Bars';
layout gridded / border=false;
layout datalattice columnvar=spacing / headerlabeldisplay=value cellwidthmin=50
columnheaders=bottom border=false columndatarange=union
columnaxisopts=(display=(line tickvalues))
rowaxisopts=(offsetmin=0 linearopts=(tickvaluepriority=true)
label='Mean CO2flux' griddisplay=on);
layout prototype / walldisplay=(fill);
barchart x=month y=CO2flux_mean / group=spacing barlabel=true
name='bar' outlineattrs=(color=black);
scatterplot x=month y=CO2flux_mean / group=spacing yerrorlower=CO2flux_lclm
yerrorupper=CO2flux_uclm
markerattrs=(size=0) name='scatter'
errorbarattrs=(thickness=2) datatransparency=0.6;
endlayout;
endlayout;
endlayout;
endgraph;
end;
run;
proc sgrender data=new template=barchart;
run;
and I got this result added as file, but it seems I did something wrong, the error bars are too big, how can fix this? Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Are you sure they're wrong? Is there any specific reason you're using PROC TEMPLATE and not just SGPLOT?
HBARPARM supports confidence limits.
Without the data to run the code, this is a harder one to say what's going wrong. I'll move it to the graphics forum and hopefully one of the graphing gurus can assist. I have an alternate solution below.
proc means data=sashelp.class mean n lclm uclm stackods;
class age;
var height;
ods output summary=classMean;
run;
proc sgplot data=classMean;
vbarparm category=age response=mean /
limitlower=lclm
limitupper=uclm;
run;
@smorkoc wrote:
Hi,
I was trying to create a barchart with error bars, my x-axis= month, y-axis=CO2flux.. Here is my code;proc sort data=mydata.butner_new1 out=btnret;
by spacing;
run;
proc means data=btnret nway mean clm noprint;
by spacing;
class month;
var CO2flux;
output out=new mean= lclm= uclm= / autoname;
run;
proc template;
define statgraph barchart;
begingraph;
entrytitle 'Bar Chart with Error Bars';
layout gridded / border=false;
layout datalattice columnvar=spacing / headerlabeldisplay=value cellwidthmin=50
columnheaders=bottom border=false columndatarange=union
columnaxisopts=(display=(line tickvalues))
rowaxisopts=(offsetmin=0 linearopts=(tickvaluepriority=true)
label='Mean CO2flux' griddisplay=on);
layout prototype / walldisplay=(fill);
barchart x=month y=CO2flux_mean / group=spacing barlabel=true
name='bar' outlineattrs=(color=black);
scatterplot x=month y=CO2flux_mean / group=spacing yerrorlower=CO2flux_lclm
yerrorupper=CO2flux_uclm
markerattrs=(size=0) name='scatter'
errorbarattrs=(thickness=2) datatransparency=0.6;
endlayout;
endlayout;
endlayout;
endgraph;
end;
run;proc sgrender data=new template=barchart;
run;
and I got this result added as file, but it seems I did something wrong, the error bars are too big, how can fix this? Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you so much, it worked great but I guess it shows all the spacing together. I would like to show 3 different spacing results in one graph; just like I tried to show it in my previous graph.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Well if you post data that allows us to replicate your chart I'm willing to take a stab at it, but without data I can't run the code.
In general, I wouldn't recommend that as well either. You should genrealze your template code and use SGRENDER and DYNAMIC variables to point to it. It makes it easier to re-use a template but you've hardcoded variable names and such into yours.
@smorkoc wrote:
Thank you so much, it worked great but I guess it shows all the spacing together. I would like to show 3 different spacing results in one graph; just like I tried to show it in my previous graph.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Ok. Here is my data. Just like you said, I run this code;
proc means data=btnret mean n lclm uclm stackods;
class month;
var CO2flux;
ods output summary=classMean;
run;
proc sgplot data=classMean;
vbarparm category=month response=mean /
limitlower=lclm
limitupper=uclm;
run;
but I want to have the same graph for 3 different spacing ; 0.5 , 1 , 2
thank you, I really appreciate it .
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
So your code is correct and as I suspected your data has those ranges in it. Your ranges are that big and includes negative, so you probably need a different way to calculate your CI, which depends on your data. I'm assuming for example that you can't have a negative value for the CO2Flux, which you do have in your confidence intervals.
This is as far as I know how to get with SGPLOT but, it shows the same graph as yours essentially when used with your data.
proc sgplot data=new;
vbarparm category=spacing response=co2flux_mean / group=month groupdisplay=cluster
limitlower=co2flux_lclm
limitupper=co2flux_uclm;
run;
@smorkoc wrote:
Ok. Here is my data. Just like you said, I run this code;
proc means data=btnret mean n lclm uclm stackods;
class month;
var CO2flux;
ods output summary=classMean;
run;
proc sgplot data=classMean;
vbarparm category=month response=mean /
limitlower=lclm
limitupper=uclm;
run;
but I want to have the same graph for 3 different spacing ; 0.5 , 1 , 2
thank you, I really appreciate it .
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I'm confused a little bit. As you see , I do not have any negative number for CO2flux in my data , is it possible to get negative numbers for CI?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@smorkoc wrote:
I'm confused a little bit. As you see , I do not have any negative number for CO2flux in my data , is it possible to get negative numbers for CI?
Yes it is. Check the data in the NEW data set, you have negative values in it for the lower bound.