How can I get an output from PROC GLM to be like below:
VarName RSQUARE height_MEAN Coeff Var
weight xx xxx ww
sex yy yyy www
It is easy in proc reg but I don't know how to do it in proc glm.
Thank you for your response.
/* 1. transpose from wide (Y, X1 ,...,X100) to long (varNum VarName Y Value) */
data Long;
set Wide; /* <== specify data set name HERE */
array x [*] x1-x&nCont; /* <== specify explanatory variables HERE */
do varNum = 1 to dim(x);
VarName = vname(x[varNum]); /* variable name in char var */
Value = x[varNum]; /* value for each variable for each obs */
output;
end;
drop x:;
run;
/* 2. Sort by BY-group variable */
proc sort data=Long; by VarName; run;
/* 3. univariate glm regression on single predictor*/
proc glm data=Long outstat=PE;
CLASS Value;
by VarName;
model Y = Value;
ods select FitStatistics;
quit;
proc print data=PE;
run;quit;
/* 3. univariate glm regression on single predictor*/
proc glm data=Long outstat=PE;
CLASS Value;
by VarName;
model Y = Value;
*ods select FitStatistics;
ods output fitstatistics = rSquared parameterEstimates = PE(where=(Parameter='Value'));
quit;
This will capture the data for you in a clean fashion into two data sets rSQuared and PE. You can then merge them to get the table you want. I think for means you'll need a PROC MEANS for mean.
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!
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.