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

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS Procedures
- /
- Slope and Intercept.

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

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

04-28-2009 03:29 PM

Hi,

I have two column values X and Y. Is there a way to find the slope and the intercept of column X and Y. Something which is equivalent to slope(y1:y100,x1:x100) in excel.

I do not have a regression model. I just have the data set with these two columns and I need to compute the slope and intercept for these two columns.

Is there a way in SAS to do this?

Thanks for any small help you render.

I have two column values X and Y. Is there a way to find the slope and the intercept of column X and Y. Something which is equivalent to slope(y1:y100,x1:x100) in excel.

I do not have a regression model. I just have the data set with these two columns and I need to compute the slope and intercept for these two columns.

Is there a way in SAS to do this?

Thanks for any small help you render.

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to deleted_user

04-28-2009 03:37 PM

You can get it directly from PROC REG. You can get it indirectly from PROC CORR (you'll need a regression and correlation text to do the crosswalk). CORR is part of the Base SAS, so you should have that procedure even if you don't have SAS/Stat.

There are other ways to get it from SAS, but these are the most direct.

There are other ways to get it from SAS, but these are the most direct.

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to deleted_user

04-28-2009 05:12 PM

This seems to work.

[pre]

data one;

do x = 1 to 4, 3.3;

input y @;

output;

end;

cards;

1.5 1.6 2.1 3.0 .

;;;;

run;

proc reg data=one;

model y = x;

output out=p p=p r=r;

run;

proc print;

run;

proc summary data=one;

where not missing(y) and not missing(x);

output

out = sums(drop=_

n(x) = n

sum(x y) = sx sy

uss(x) = uss

;

run;

proc summary data=one;

where not missing(y) and not missing(x);

weight x;

output out=sxy(drop=_ sum(y)=sxy;

run;

data pred;

set one;

if _n_ eq 1 then do;

set sums;

set sxy;

retain b i;

b = (n*sxy - sx*sy) / (n*uss - sx**2);

i = (sy - b*sx) / n;

end;

p = i + x*b;

r = y - p;

run;

proc print;

run;

[/pre]

[pre]

data one;

do x = 1 to 4, 3.3;

input y @;

output;

end;

cards;

1.5 1.6 2.1 3.0 .

;;;;

run;

proc reg data=one;

model y = x;

output out=p p=p r=r;

run;

proc print;

run;

proc summary data=one;

where not missing(y) and not missing(x);

output

out = sums(drop=_

n(x) = n

sum(x y) = sx sy

uss(x) = uss

;

run;

proc summary data=one;

where not missing(y) and not missing(x);

weight x;

output out=sxy(drop=_ sum(y)=sxy;

run;

data pred;

set one;

if _n_ eq 1 then do;

set sums;

set sxy;

retain b i;

b = (n*sxy - sx*sy) / (n*uss - sx**2);

i = (sy - b*sx) / n;

end;

p = i + x*b;

r = y - p;

run;

proc print;

run;

[/pre]

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to deleted_user

04-28-2009 05:33 PM

But I do not have proc reg installed. I do not know how to figure out. When I try running it with proc reg the log says procedure reg not found.

Is there any alternate way of doing this?

Is there any alternate way of doing this?

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to deleted_user

04-28-2009 07:06 PM

The PROC REG in my program was for me to check my calculations. Just remove it.

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to deleted_user

05-04-2009 09:58 AM

You can also run a proc gplot with a symbol i=rl statement. The slope / intercept info is posted in the log window.

86 data test;

87 input a b;

88 datalines;

NOTE: The data set WORK.TEST has 4 observations and 2 variables.

NOTE: DATA statement used (Total process time):

real time 0.03 seconds

cpu time 0.01 seconds

93 ;

94

95 goptions dev=win;

96 symbol1 i=rl;

97 proc gplot data=test;

98 plot a*b=1;

99 run;

NOTE: Regression equation : a = 1.311793 + 0.483037*b.

100 quit;

86 data test;

87 input a b;

88 datalines;

NOTE: The data set WORK.TEST has 4 observations and 2 variables.

NOTE: DATA statement used (Total process time):

real time 0.03 seconds

cpu time 0.01 seconds

93 ;

94

95 goptions dev=win;

96 symbol1 i=rl;

97 proc gplot data=test;

98 plot a*b=1;

99 run;

NOTE: Regression equation : a = 1.311793 + 0.483037*b.

100 quit;