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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 1 reply
  • 747 views
  • 0 likes
  • 2 in conversation