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

I would like to obtain fitted variables for a GLM regression model excluding the class variable. I am familiar with getting fitted values for a full statistical model in general, which can be done with something of the form

 

proc glm data=this.data;

  class categorical_var;

  model y x1 x2 categorical_var / solution;

  output out=this.outdata predicted=yhat;

run;

 

What I want is yhat to contain *just* the fittted values for the x1 and x2 variables, excluding the categorical_var values. Is anyone aware of a way (preferably simple!) to do this without viewing the regression output and hard-coding in the parameters for x1 and x2 myself? I am using SAS 9.4.

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

First method:

 

Remove the categorical variable from the model. That will give you estimates that are weighted by the size of each class in your data.

 

Second method

 

If you want the classes to have equal weight in your estimates, you could use a variant of the adding missing values to the data technique:

 

data carsReg;
set sashelp.cars;
id = _n_;
output;
call missing(MSRP);
extra = 1;
do type = "Hybrid", "SUV", "Sedan", "Sports", "Truck", "Wagon";
    output;
    end;
keep id MSRP horsepower weight type extra;
run;

proc glm data=carsReg plots=none;
class type;
model MSRP = horsepower weight type;
output out=carsPred predicted=MSRP_pred stdp=MSRP_STDP;
run;
quit;

proc sql;
create table carsAvgType as
select
    id, horsepower, weight,
    mean(MSRP_pred) as MSRP_pred,
    sqrt(mean(MSRP_STDP**2)) as MSRP_STDP
from carsPred
where extra
group by id, horsepower, weight;
quit;
PG

View solution in original post

1 REPLY 1
PGStats
Opal | Level 21

First method:

 

Remove the categorical variable from the model. That will give you estimates that are weighted by the size of each class in your data.

 

Second method

 

If you want the classes to have equal weight in your estimates, you could use a variant of the adding missing values to the data technique:

 

data carsReg;
set sashelp.cars;
id = _n_;
output;
call missing(MSRP);
extra = 1;
do type = "Hybrid", "SUV", "Sedan", "Sports", "Truck", "Wagon";
    output;
    end;
keep id MSRP horsepower weight type extra;
run;

proc glm data=carsReg plots=none;
class type;
model MSRP = horsepower weight type;
output out=carsPred predicted=MSRP_pred stdp=MSRP_STDP;
run;
quit;

proc sql;
create table carsAvgType as
select
    id, horsepower, weight,
    mean(MSRP_pred) as MSRP_pred,
    sqrt(mean(MSRP_STDP**2)) as MSRP_STDP
from carsPred
where extra
group by id, horsepower, weight;
quit;
PG

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 2104 views
  • 1 like
  • 2 in conversation