BookmarkSubscribeRSS Feed
mh2t
Obsidian | Level 7

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. 

7 REPLIES 7
Reeza
Super User
You have an RSquare for each variable? How does that work?
mh2t
Obsidian | Level 7
so we run two univariate glm models, each has a separate RSquare in the output.
Reeza
Super User
Do you have code to already run all those regressions? If we can add our solution to yours that's more efficient.
mh2t
Obsidian | Level 7
/* 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;
Reeza
Super User
/* 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.

 

mh2t
Obsidian | Level 7
Thank you @Reeza. I'm very new to SAS environment, I don't know how to merge them.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 1200 views
  • 0 likes
  • 2 in conversation