I have an SG Plot using the code below. Two of my stddev error bars extend below zero. I want to truncate them at zero and add a symbol to the end of the error bars. Any ideas? Thanks in advance.
proc sgplot data=ssprox noautolegend;
format /*VIS yyf.*/ cdstcn2 ccc.;
styleattrs datasymbols=(circle circle circlefilled squarefilled ) datalinepatterns=(solid shortdash dash longdash) datacontrastcolors=(red gray4C blue green);
vline vis / response=var1 group=cdstcn2 stat=Mean limitstat=stddev markers markerattrs=(size=10) discreteoffset=-0.2 name="In" /*datalabel*/;
vline vis / response=var2 group=cdstcn2 stat=Mean limitstat=stddev markers markerattrs=(size=10) discreteoffset=-0.1 /*datalabel*/;
vline vis / response=var3 group=cdstcn2 stat=Mean limitstat=stddev markers markerattrs=(size=10) discreteoffset=0.1 /*datalabel*/;
vline vis / response=var4 group=cdstcn2 stat=Mean limitstat=stddev markers markerattrs=(size=10) discreteoffset=0.2 /*datalabel*/;
yaxis label= 'Mean PRO2' values=(0 to 30 by 5) offsetmin=.05 offsetmax=.05 minor minorcount=4 labelattrs=(family='SWISSL');
xaxis values=(0 to 52 by 2) offsetmin=.02 offsetmax=.02 labelattrs=(family='SWISSL');
keylegend "In"/title = "CDST-category" /* position=topright */ location=outside noborder;
run;
As @ballardw said, you will not be able to do this directly using VLINE. You will need to calculate the standard deviations externally and flag the values that drop below zero. Then, combine a SERIES and a HIGHTLOW plot to draw the graph. I would recommend using a HIGHLOW plot to represent the STDDEV values, as you can put different styles of endcaps on the lines from the data set.
In the data step to process your +/- STDDEV value, create a column called LOWCAP (or whatever you want to call it) to store the symbol to use on the low end of the HIGHLOW lines. If the low value is >= 0, set the value in this column to be "SERIF". If the value is < 0, set the low value to be 0, and set the LOWCAP value to be OPENARROW. Then, set the LOWCAP option on the HIGHLOW plot to point to this column, while setting "SERIF" on the HIGHCAP option.
Hope this helps!
Dan
I don't think that "truncation" will be possible with the VLINE LIMITSTAT options. If you want to control one end of an error bar separate from the other then you may need to look at a plot that uses different limit variables for upper and lower values, such as the SCATTER Yerrorlower and Yerrorupper or the BAND plot UPPER and LOWER variables.
You don't provide any data so not going to attempt specific code to accomplish anything.
As @ballardw said, you will not be able to do this directly using VLINE. You will need to calculate the standard deviations externally and flag the values that drop below zero. Then, combine a SERIES and a HIGHTLOW plot to draw the graph. I would recommend using a HIGHLOW plot to represent the STDDEV values, as you can put different styles of endcaps on the lines from the data set.
In the data step to process your +/- STDDEV value, create a column called LOWCAP (or whatever you want to call it) to store the symbol to use on the low end of the HIGHLOW lines. If the low value is >= 0, set the value in this column to be "SERIF". If the value is < 0, set the low value to be 0, and set the LOWCAP value to be OPENARROW. Then, set the LOWCAP option on the HIGHLOW plot to point to this column, while setting "SERIF" on the HIGHCAP option.
Hope this helps!
Dan
Thanks for the prompt and detailed solution!
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.