Solved
New Contributor
Posts: 3

# How do I plot data with a regression line on top of the scatter plot?

[ Edited ]

I have some data:

```x = 1 0 2 0 3 1 0 1 2 0;
y = 16 9 17 12 22 13 8 15 19 11;```

I'd like to generate an estimated regression function and plot the line on top of the data scatter plot.

I tried searching for a tutorial or some kind of example, but couldn't find any (that I understood and that worked when i tried plugging them in).

Accepted Solutions
Solution
‎09-04-2017 05:21 PM
PROC Star
Posts: 1,209

## Re: How do I plot data with a regression line on top of the scatter plot?

Not sure if this is what you are after?

``````data have;
input x y;
datalines;
1 16
0 9
2 17
0 12
3 22
1 13
0 8
1 15
2 19
0 11
;

ods select FitPlot;
proc reg data=have;
model y = x;
run;quit;``````

All Replies
Posts: 1,270

Hi,

Try proc sgplot.

Super User
Posts: 23,262

## Re: How do I plot data with a regression line on top of the scatter plot?

And the SGPLOT - which gives you more control over the colours and graph attributes:

``````title 'My demo plot';
proc sgplot data=have;
scatter x=x y=y ;
reg x=x y=y / lineattrs=(color=CXf03b20);
run;``````
Solution
‎09-04-2017 05:21 PM
PROC Star
Posts: 1,209

## Re: How do I plot data with a regression line on top of the scatter plot?

Not sure if this is what you are after?

``````data have;
input x y;
datalines;
1 16
0 9
2 17
0 12
3 22
1 13
0 8
1 15
2 19
0 11
;

ods select FitPlot;
proc reg data=have;
model y = x;
run;quit;``````
☑ This topic is solved.