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

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;

1 ACCEPTED SOLUTION

Accepted Solutions
DanH_sas
SAS Super FREQ

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

 

View solution in original post

3 REPLIES 3
ballardw
Super User

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.

DanH_sas
SAS Super FREQ

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

 

yportne1177
Calcite | Level 5

Thanks for the prompt and detailed solution!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 390 views
  • 2 likes
  • 3 in conversation