Using this code snippet:
PROC GLMSELECT DATA = WORK.Training TESTDATA = WORK.Test;
MODEL
.... / selection=none stb showpvalues;
ods output
"Fit Statistics" = WORK.Model_Fit
"Parameter Estimates" = WORK.ParameterEstimates
Nobs = WORK.Nobs;
RUN;
The dataset WORK.Model_Fit contains:
Root MSE
Dependent Mean
R-Square
Adj R-Sq
AIC
AICC
SBC
ASE (Train)
ASE (Test)
Is the R-Square measured on the training dataset? Is it possible to obatin the R-Square fro the training and test dataset?
Here is an example:
/* Split a dataset into training and test subsets */
data splitClass;
set sashelp.class;
if mod(_n_, 3) > 0 then role = "training";
else role = "test";
run;
proc glmselect data=splitclass;
class sex;
model weight = sex height / selection=none;
partition rolevar=role(test="test" train="training");
output out=outClass residual=resWeight;
run;
proc sql noprint;
select 1 - uss(resWeight)/css(weight) as rsquare format=7.4
into :r2_training trimmed
from outClass where role="training";
select 1 - uss(resWeight)/css(weight) as rsquare format=7.4
into :r2_test trimmed
from outClass where role="test";
quit;
%put &=r2_training &=r2_test;
One option is to calculate R square yourself from the residuals as 1 - USS(resid)/CSS(dependent) for each data subset.
You can use SCORE or CODE statement to score new dataset and calculated R-square. OR proc glmselect; model......... run; proc reg....... model y=&_GLSIND ; ........ to get that R-square.
Here is an example:
/* Split a dataset into training and test subsets */
data splitClass;
set sashelp.class;
if mod(_n_, 3) > 0 then role = "training";
else role = "test";
run;
proc glmselect data=splitclass;
class sex;
model weight = sex height / selection=none;
partition rolevar=role(test="test" train="training");
output out=outClass residual=resWeight;
run;
proc sql noprint;
select 1 - uss(resWeight)/css(weight) as rsquare format=7.4
into :r2_training trimmed
from outClass where role="training";
select 1 - uss(resWeight)/css(weight) as rsquare format=7.4
into :r2_test trimmed
from outClass where role="test";
quit;
%put &=r2_training &=r2_test;
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!
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.