Calcite | Level 5

## How do I calculate the slope from a series of data points?

Hi everyone,

OK, so plotting a graph, pretty straightforward:

X axis = concentration of the chemical (log transformed)

Y axis = percent mortality

BUT - how do I calculate the actual slope? Could you offer me code to do that? I am using SAS version 9.3 on a PC.

Example data points:

x = 4.20, y = 10

x = 4.27, y = 20

x = 4.29, y = 30

x = 4.58, y = 40

x = 4.73, y = 50

x = 4.82, y = 60

Thank you!

Peppy

1 ACCEPTED SOLUTION

Accepted Solutions
SAS Super FREQ

## Re: How do I calculate the slope from a series of data points?

Use the INSET statement to display the slope after you've computed it: How to use PROC SGPLOT to display the slope and intercept of a regression line - The DO Loop

5 REPLIES 5
Super User

## Re: How do I calculate the slope from a series of data points?

m = (y2-y1)/(x2-x1) or assuming you have the pairs and want the slope from the previous point;

data want;

set have;

slope = (y - lag(y))/(x-lag(x));

run;

Ammonite | Level 13

## Re: How do I calculate the slope from a series of data points?

data have;
input x y;
datalines;
4.20 10
4.27 20
4.29 30
4.58 40
4.73 50
4.82 60
;

ods output parameterEstimates=slope;
proc reg data=have;
model y=x;
run;

proc print data=slope;
run;

Slope dataset will have intercept and slope.

Super User

## Re: How do I calculate the slope from a series of data points?

I couldn't find an easy way to add the slope in to the graph automatically.  GPLOT provides the entire regression equation but its at the bottom and not pretty.

data have;

input x y;

cards;

4.20 10

4.27 20

4.29 30

4.58 40

4.73 50

4.82 60

;

run;

ods output parameterEstimates=slope;

proc reg data=have;

model y=x;

run;

proc sql noprint;;

select Estimate into :slope from slope where variable='x';

quit;

proc sgplot data=have;

scatter x=x y=y;

reg x=x y=y/degree=1 curvelabel="Slope=&slope" curvelabelpos=end;

run;quit;

SAS Super FREQ

## Re: How do I calculate the slope from a series of data points?

Use the INSET statement to display the slope after you've computed it: How to use PROC SGPLOT to display the slope and intercept of a regression line - The DO Loop

Calcite | Level 5

## Re: How do I calculate the slope from a series of data points?

Thank you all so much! This is so helpful - this will really assist me. I appreciate your time!

Discussion stats
• 5 replies
• 23589 views
• 1 like
• 5 in conversation