Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Home
- /
- Programming
- /
- SAS Procedures
- /
- proc sgplot: how to show equation of 95 % prediction limits

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 10-28-2016 07:09 AM
(1817 views)

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;
```

4 REPLIES 4

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

*> 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;
```

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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.

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 16. Read more here about **why** you should contribute and **what is in it** for you!

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.