Help using Base SAS procedures

Slope and Intercept.

Posts: 0

Slope and Intercept.


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.
Trusted Advisor
Posts: 2,114

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.
Respected Advisor
Posts: 3,780

Re: Slope and Intercept.

This seems to work.

data one;
do x = 1 to 4, 3.3;
input y @;
1.5 1.6 2.1 3.0 .

proc reg data=one;
model y = x;
output out=p p=p r=r;
proc print;

proc summary data=one;
where not missing(y) and not missing(x);
out = sums(drop=_Smiley Happy
n(x) = n
sum(x y) = sx sy
uss(x) = uss
proc summary data=one;
where not missing(y) and not missing(x);
weight x;
output out=sxy(drop=_Smiley Happy sum(y)=sxy;

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;
p = i + x*b;
r = y - p;
proc print;
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?
Respected Advisor
Posts: 3,780

Re: Slope and Intercept.

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

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 ;
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;
Ask a Question
Discussion stats
  • 5 replies
  • 4 in conversation