Turn on suggestions

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

Showing results for

- Home
- /
- Analytics
- /
- Stat Procs
- /
- Re: How do I calculate the slope from a series of data points?

Options

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

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

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

Posted 10-28-2014 04:01 PM
(23341 views)

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

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

5 REPLIES 5

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

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;

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

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.

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

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;

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

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

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

**Don't miss out on SAS Innovate - Register now for the FREE Livestream!**

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.