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

Is there a way to automatically asks SAS to pick the minimum and maximum value for y and x axis as shown below? 

This will make the code flexible to handle any different data and zoom the view as the data range keeps changing.

 

Example

 

proc sgplot data=sashelp.class(where=(sex='F')) noautolegend;
bubble x=height y=weight size=age / group=name datalabel=name
transparency=0.4 datalabelattrs=(size=9 weight=bold);
inset "Bubble size represents Age" / position=bottomright textattrs=(size=11);
yaxis grid; **** How to take the min and max instead of just giving grid? something like this "yaxis min = min(grid) max = max(grid) offsetmin=0 offsetmax=0.1 display=(nolabel) grid;" *****;
xaxis grid;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisHemedinger
Community Manager

I like @ballardw's idea because I think that is probably more meaningful -- fitting a line to a model and providing a simple visual to show the distance of each point to that line.

 

However, if you just want true averages, a variation of what I shared earlier:

 

proc sql noprint;
 select avg(weight) into: avgW from sashelp.class(where=(sex='F')) ;
 select avg(height) into: avgH from sashelp.class(where=(sex='F')) ;
quit;

proc sgplot data=sashelp.class(where=(sex='F')) noautolegend;
   bubble x=height y=weight size=age / group=name datalabel=name
   transparency=0.4 datalabelattrs=(size=9 weight=bold);

   refline &avgW. / axis=y label="Avg weight=&avgW." 
        labelloc=inside 
        lineattrs=(pattern=dot thickness=2)
        labelpos=min;

   refline &avgH. / axis=x label="Avg height=&avgH." 
        labelloc=inside 
        lineattrs=(pattern=dot thickness=2)
        labelpos=max;

   inset "Bubble size represents Age" / position=bottomright textattrs=(size=11);
   yaxis grid ; 
   xaxis grid;
run;

avg.jpg 

Learn from the Experts! Check out the huge catalog of free sessions in the Ask the Expert webinar series.

View solution in original post

7 REPLIES 7
PGStats
Opal | Level 21

What values would min(grid) and max(grid) be?

PG
skallamp1
Fluorite | Level 6

xaxis min= min(height) max= max(height) offsetmin=0 offsetmax=0.1 display=(nolabel) grid;

 

It should pick the min and max values from x and y axis.

Reeza
Super User
What happens if you don't specify them at all? Wouldn't SAS adjust it automatically to what you had wanted?
ChrisHemedinger
Community Manager

If you want to scale the axis for the full data set, while filtering what you plot (as in your example with sex='F'), you can store the min/max in macro variables and use as the MIN/MAX= values.  Is that what you're after?

 

proc sql noprint;
 select min(weight) into: min from sashelp.class;
 select max(weight) into: max from sashelp.class;
quit;

proc sgplot data=sashelp.class(where=(sex='F')) noautolegend;
bubble x=height y=weight size=age / group=name datalabel=name
transparency=0.4 datalabelattrs=(size=9 weight=bold);
inset "Bubble size represents Age" / position=bottomright textattrs=(size=11);
yaxis grid min=&min. max=&max.; 
xaxis grid;
run;

bbl.jpg

Learn from the Experts! Check out the huge catalog of free sessions in the Ask the Expert webinar series.
skallamp1
Fluorite | Level 6

This will be helpful.

Can we also plot a line chart for average weight and height in the same visual?

In that way we can say who is above and below the average.

 

Thanks,

+Sathyan

ballardw
Super User

@skallamp1 wrote:

This will be helpful.

Can we also plot a line chart for average weight and height in the same visual?

In that way we can say who is above and below the average.

 

Thanks,

+Sathyan


Try adding a reg plot:

 

proc sgplot data=sashelp.class(where=(sex='F')) noautolegend;
   bubble x=height y=weight size=age / group=name datalabel=name
   transparency=0.4 datalabelattrs=(size=9 weight=bold);

   reg x=height y=weight;

   inset "Bubble size represents Age" / position=bottomright textattrs=(size=11);
   yaxis grid ; 
   xaxis grid;
run;

Default is a linear regression which would be , given the data , the mean Y for X. Though how good the fit may be...

Which is why the Reg plot may include confidence limits for  either the mean or the individual values.

ChrisHemedinger
Community Manager

I like @ballardw's idea because I think that is probably more meaningful -- fitting a line to a model and providing a simple visual to show the distance of each point to that line.

 

However, if you just want true averages, a variation of what I shared earlier:

 

proc sql noprint;
 select avg(weight) into: avgW from sashelp.class(where=(sex='F')) ;
 select avg(height) into: avgH from sashelp.class(where=(sex='F')) ;
quit;

proc sgplot data=sashelp.class(where=(sex='F')) noautolegend;
   bubble x=height y=weight size=age / group=name datalabel=name
   transparency=0.4 datalabelattrs=(size=9 weight=bold);

   refline &avgW. / axis=y label="Avg weight=&avgW." 
        labelloc=inside 
        lineattrs=(pattern=dot thickness=2)
        labelpos=min;

   refline &avgH. / axis=x label="Avg height=&avgH." 
        labelloc=inside 
        lineattrs=(pattern=dot thickness=2)
        labelpos=max;

   inset "Bubble size represents Age" / position=bottomright textattrs=(size=11);
   yaxis grid ; 
   xaxis grid;
run;

avg.jpg 

Learn from the Experts! Check out the huge catalog of free sessions in the Ask the Expert webinar series.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 7 replies
  • 1447 views
  • 0 likes
  • 5 in conversation