Not applicable
Posts: 0

# Slope and Intercept.

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?

Posts: 2,124

## Re: Slope and Intercept.

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.
Posts: 3,852

## Re: Slope and Intercept.

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]
Not applicable
Posts: 0

## Re: Slope and Intercept.

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?
Posts: 3,852

## Re: Slope and Intercept.

The PROC REG in my program was for me to check my calculations. Just remove it.
Super Contributor
Posts: 297

## Re: Slope and Intercept.

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;
Discussion stats
• 5 replies
• 843 views
• 0 likes
• 4 in conversation