BookmarkSubscribeRSS Feed
josuerodrigues
Calcite | Level 5

Hi. I'm working with doses of limestone and styding soil pH. My model is a quadratic polynomial and I did a scatterplot in PROC SGPLOT. But I want to know if I can put the equation inside of the graph. How can I do that? I know how to do in Excell, but in the SAS on Demand I don't know if it's possible. Below is the code line that I used. Thanks for the helpful.

 

proc sgplot data=mydata noautolegend;
title height=11pt color=black "soil pH vs limestone";
scatter Y=pH X=DOSE;
yaxis label="pH";
xaxis min=0 max=1.92 values=(0 0.48 0.96 1.44 1.92) label="Limestone (t/ha)";
REG Y=pH X=DOSE/degree=2;
keylegend / location=inside position=top across=5 down=3 titleattrs=(wight=bold size=9pt) valueattrs=(collor=black size=7pt);
run;

josuerodrigues_0-1716391391985.png

 

1 REPLY 1
Rick_SAS
SAS Super FREQ

First, use PROC GLM to get the parameter estimates for the regression model:

data Have;
set sashelp.cars;
x = EngineSize;
y = MPG_City;
run;

proc glm data=Have;
model y = x x*x / solution;
quit;

Then you have two choices:

1. Display the regression coefficients in a table as name-value pairs

2. Display the regression line as an equation

 

For the first case (the table), here is an example:

proc sgplot data=Have noautolegend;
   reg Y=y X=x / degree=2;
   inset("Intercept"= "39.26"
         "x"   = "-8.65"
         "x^2" = "0.74") 
         / title="Regression Coefficients" opaque border;
run;

For the second case (an equation), here is an example:

proc sgplot data=Have noautolegend;
   reg Y=y X=x / degree=2;
   inset "y = 39.26 - 8.65*x + 0.74*x^2" / opaque border;
run;

If necessary, there are also ways to get an inline superscipt instead of x^2.

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!

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
  • 1 reply
  • 375 views
  • 0 likes
  • 2 in conversation