Hi,
I am using proc sgplot to calculate the best fit regression line as well as the 95% prediction limits. I want the equation for all three lines plotted on the graph (or showed in the results). Now I can only see the the Parameter estimates for the best fit line.
This is my code:
data _null_;
set outputds;
if variable eq 'Intercept' then call symput('Int', put(estimate, BEST.));
else call symput('Slope', put(estimate, BEST.));
ods output outputds;
run;
proc sgplot data=diffs noautolegend;
title "Regression Line with Slope and Intercept";
reg y=diff x=mean / cli;
ods output parameterestimates=outputds;
inset "Intercept = &Int" "Slope = &Slope" /
border title="Parameter Estimates" position=topleft;
run;
Not entireley sure on the spefics in this question - where the "equation" comes from. Is that part of an output table from proc reg or something you hard code in? As for plotting it, well that pretty simple. Add into your plot data, the text you want to show, at the places you want to show, then have another statement in your sgplot:
scatter y=dif x=mean / markechars=(<variable>)
Examples here:
http://blogs.sas.com/content/graphicallyspeaking/?s=scatter+markerchar
Thank you! I was maybe a little bit unclear in my explanation: I already have the intercept and slope (with this I mean equation) for the fit-line in my Parameter Estimates, but I also need the intercept and slope for the upper and lower 95 % prediction limits. I can not see this in the example and I am also not very good at programming in SAS so it would be great if you know a code for this.
> I also need the intercept and slope for the upper and lower 95 % prediction limits.
Unfortunately, the prediction limits are not linear, so they do not have an intercept or slope. Run the following code. The graph that is produced shows that the prediction limits are wide at the extreme of the X variable and narrow in the middle. There is no simple equation for those curves in terms of X.
ods graphics on;
proc reg data=sashelp.class plots(only)=fitplot;
model weight = height;
run;
To show the estimated slope and intercept, see the article "How to use PROC SGPLOT to display the slope and intercept of a regression line", which gives complete step-by-step code and an example.
In particular, you are trying to use the REG statement in PROC SGPLOT, but you need to use PROC REG if you want to use ODS OUTPUT to capture the ParameterEstimates table.
The title of your question is "show equation of 95% prediction limits," which different from the slope/intercept equation that you seem to want. See the documentation for "Statistical Background in Linear Regression" if you want to see the formulas used to compute those limits.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.