BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
JohnChen_TW
Quartz | Level 8

HI, dose anyone has insight to create the following figure?

 

dotwithmedian_baser.png 

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

OK, one more try, following @Jay54's suggestion (tested with 9.4) :

 

proc sql;
create table class as
select *, median(weight) as med
from sashelp.class
group by age;
quit;

proc sgplot data=class noautolegend;
highlow x=age high=med low=med / type=bar lineattrs=(thickness=2 color=red) barwidth=0.6;
scatter y=weight x=age / markerattrs=(symbol=circlefilled color=blue);
xaxis type=discrete;
run;

SGPlot6.png 

PG

View solution in original post

11 REPLIES 11
Jagadishkatam
Amethyst | Level 16

We could try the sgplot procedure as below,  I am assuming that the graph is overlapping of scatter plot on box plot with mean. If it is the case the below procedure should help.

 

proc sgplot data=have;

scatter x=feed_type y=weight /  markerattrs = (size = 2 symbol = circlefilled); /*this will be the scatter plot*/

vbox weight / category=feed_type; /*this will create the box plot with mean*/

quit;

run;

 

Thanks,
Jag
JohnChen_TW
Quartz | Level 8

Hi Jagadishkatam,

 

It seems that the overlapping scatter plot and box plot is not worked.
Please see the SAS log below.
Thanks for your reply.

 

未命名.png

 

By the way, I'm using SAS 9.3.

PGStats
Opal | Level 21

I guess in 9.3 you could cheat this way:

 

proc sql;
create table class as
select *, median(weight) as med
from sashelp.class
group by age;
quit;

proc sgplot data=class noautolegend;
scatter x=age y=med / yerrorlower=med yerrorupper=med 
    markerattrs=(size=0) errorbarattrs=(thickness=2 color=red);
scatter y=weight x=age / markerattrs=(symbol=circlefilled color=blue);
run;

SGPlot8.png

PG
JohnChen_TW
Quartz | Level 8
Hi PG Stats,

Thanks for your solution.
Another question, how to lengthen the length of 'mean'?
PGStats
Opal | Level 21

I don't know. Seems to be proportional to line thickness.

PG
JohnChen_TW
Quartz | Level 8
Okay. I will try.
According to your reply, SAS 9.3 cannot overlay vbox and scatter plot, right?
PGStats
Opal | Level 21

Here is an approaching example: 

 

proc sql;
create table class as
select *, median(weight) as med
from sashelp.class
group by age;
quit;

proc sgplot data=class noautolegend;
vbox med / category=age nomean nomedian nocaps
    lineattrs=(color=red thickness=2);
scatter y=weight x=age / markerattrs=(symbol=circlefilled);
xaxis type=discrete;
run;

SGPlot5.png

PG
Jay54
Meteorite | Level 14

If you know the value for drawing the mean or median (the red line), and are using SAS 9.3, I suggest overlaying a Scatter and a HighLow (Type=Bar).  Make the high and low the same value to get a single line.  You can set the BarWidth to control the width of the line.

PGStats
Opal | Level 21

OK, one more try, following @Jay54's suggestion (tested with 9.4) :

 

proc sql;
create table class as
select *, median(weight) as med
from sashelp.class
group by age;
quit;

proc sgplot data=class noautolegend;
highlow x=age high=med low=med / type=bar lineattrs=(thickness=2 color=red) barwidth=0.6;
scatter y=weight x=age / markerattrs=(symbol=circlefilled color=blue);
xaxis type=discrete;
run;

SGPlot6.png 

PG
JohnChen_TW
Quartz | Level 8
I'm creating the figure by your suggestion. Great thanks for everyone's suggestion!
Besides, the function "median" seems not okay in SAS 9.3. There will be a warning message "The MEDIAN function has been called with only one argument.".
However, 'mean' function can be worked in proc sql statement and that what I need!

Thanks again!

JC

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 11 replies
  • 5288 views
  • 5 likes
  • 5 in conversation