BookmarkSubscribeRSS Feed
d0816
Quartz | Level 8

Hello, I would like to create a graph like below with mean and SD by category AND to this graph I would like to add actual data points( which was used to calculate means and SD) in each category.  for e.g if 5 data points were used to calculate mean for category AAA I would like to show those 5 points as dots vertically for a category. Can you please suggest how to do this? Appreciate any help.Thank you.

 

graph.png

7 REPLIES 7
d0816
Quartz | Level 8

I found this resource, but the sample code in the sample dataset do not produce the result. Also it has min and max points but not all data points.

http://support.sas.com/kb/24/871.html

 

ballardw
Super User

Visual Analytics does not use Proc Gchart at all and I'm not sure of any of the other graphing procedures as the interface is quite restrictive. So general searches that do not include VA aren't going to find solutions.

 

I had a non-VA example but from a certain amount of experience attempting to answer questions with Visual Analytics other approaches in general do not work as you have to work through the menus.

 

Not a graph like you want but the menu items he points to in this article, https://communities.sas.com/t5/SAS-Communities-Library/3-steps-to-building-a-monthly-temperature-str... , may give you some places to start poking around.

d0816
Quartz | Level 8
@ballardw
It does not need to be a VA solution.
I found a code that is trying to do similar thing except dont include data points in the chart but this example code do not give the said result.
http://support.sas.com/kb/47/076.html
Thank you.

ballardw
Super User

A general programming solution that should work outside of Visual Analytics:

 

proc summary data=sashelp.class nway;
   class sex;
   var weight;
   output out=work.summary (drop= _: )
      mean= lclm= uclm= / autoname;
run;

data work.plot;
   set sashelp.class
       work.summary
   ;
run;

proc sgplot data=work.plot;
   vbarparm category=sex response=weight_mean/
      limitlower=weight_lclm limitupper= weight_uclm
   ;
   scatter x=sex y=weight
   ;
run;

Some note that are needed:

There are limits of which types of plots in Proc Sgplot can overlay. To have a scatter plot and bar plot you must summarize the data to create the bar and the VBARPARM or HBARPARM. So that is why I summarize the data that will be used to create the scatter plot (SASHELP.CLASS). You should have this data set as part of your install. The Proc Summary calculates the mean and upper and lower confidence limits of the mean. You can change the default 95% confidence limits by adding the ALPHA= parameter to the proc statement. The / autoname option creates output variable names by appending the statistic to the variable name after an underscore character.

The summarized data and the base data have to be in a single set and the X axis variable has to be the same for plots to overlay correctly. For a VBAR type plot the X axis variable is called Category.

 

There are lots of options available to modify the appearance of plot elements. I suggest looking into the syntax references.

Reeza
Super User
You posted your question in SAS VA. Should I move it to the general graphics forum instead?

In general, if you're graphing with SAS, SGPLOT and GTL should be your starting point these days. SAS GRAPH is pretty outdated at this point and the graphical options and display is much better in SG procedures.
d0816
Quartz | Level 8
Yes @Reeza, please move the post.
Thanks.
DanH_sas
SAS Super FREQ

Instead of using a SCATTER overlay, you might want to consider using an AXISTABLE:

 

proc sgplot data=sashelp.class;
vbar age / response=weight stat=mean limitstat=stddev;
xaxistable age / stat=freq location=inside;
run;

SGPlot.png

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 7 replies
  • 3992 views
  • 0 likes
  • 4 in conversation