BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Leon27607
Fluorite | Level 6

So I used this link https://blogs.sas.com/content/iml/2013/02/27/slope-of-a-regression-line.html and had a further quesiton about it.

Is there a way to get the slope coefficient for each group separately?

 

I used this code to generate the model and found a significant interaction effect. I wanted to generate some plots for these significant ones.

 

proc mixed data=&data namelen = 200;
class &group;
model &response = &exposure &group &exposure*group + confounders;
ods output tests3 = Fulltest&i;
run;


I have this code to try and generate the graphs:


ods graphics off;
proc reg data=&data;
model &response = &alcoholvar;
ods output ParameterEstimates=PE;
run;

data _null_;
set PE;
if _n_ = 1 then call symput('Int', put(estimate, BEST6.));
else call symput('Slope', put(estimate, BEST6.));
run;

 

PROC sGPLOT DATA = &data (where =( &group ne .)) noautolegend dattrmap = attrmap ;
reg x = &x y = &y /group = &group clm clmtransparency = 0.4 attrid = &group;
title "&title";
inset "Intercept = &Int" "Slope = &Slope" /
border title="Parameter Estimates" position=topleft;
run;

 

This only generates the intercept and slope for the first group listed. Is there any way to generate the slope for each group, (in my case there are 3 groups)? So there should be a slope for the line with group = 0, an 2nd slope for the line with group = 1, and a 3rd slope for the line with group = 2.

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Proc reg may generate the plots you want, or at least give you an idea of what the data looks like. But I suspect that you need to tell Proc Reg which variable is your group variable with a BY statement. Sort the data by the group variable before Proc Reg and add a By statement.

The parameter estimates will then have 3 values, one for each group and you will need to create 3 macro variables for intercept and slope to reference in the inset statement. Look at the values of the parameters data set.

View solution in original post

1 REPLY 1
ballardw
Super User

Proc reg may generate the plots you want, or at least give you an idea of what the data looks like. But I suspect that you need to tell Proc Reg which variable is your group variable with a BY statement. Sort the data by the group variable before Proc Reg and add a By statement.

The parameter estimates will then have 3 values, one for each group and you will need to create 3 macro variables for intercept and slope to reference in the inset statement. Look at the values of the parameters data set.

sas-innovate-2024.png

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.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 1 reply
  • 4044 views
  • 0 likes
  • 2 in conversation