BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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.
5 REPLIES 5
Doc_Duke
Rhodochrosite | Level 12
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.
data_null__
Jade | Level 19
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]
deleted_user
Not applicable
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?
data_null__
Jade | Level 19
The PROC REG in my program was for me to check my calculations. Just remove it.
Bill
Quartz | Level 8
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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 4620 views
  • 0 likes
  • 4 in conversation