Graphics Programming

Data visualization using SAS programming, including ODS Graphics and SAS/GRAPH. Charts, plots, maps, and more!
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?

 

undefined 

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;

undefined 

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.

 

undefined

 

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;

undefined

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;

undefined

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;

undefined 

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-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 11 replies
  • 6653 views
  • 5 likes
  • 5 in conversation