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

I'm calculating CV and RMSE for several variables and would like to output the PROC GLM results to a SAS table. Is there a way to do this?

 

*Create sample data with repeat measures;
data have ( keep = subjectid weight momwtgain cigsperday );
 format subjectid;
 set sashelp.bweight;
 if _N_ <= 6;
 subjectid = _N_;
 if _N_ = 2 then subjectid = 1;
 if _N_ in ( 3, 4 ) then subjectid = 2;
 if _N_ in ( 5, 6 ) then subjectid = 3;
 if _N_ = 1 then cigsperday = 1;
run;


*Calculate CV and RMSE;
%macro cv ( covar );
proc glm data = have;
 model &covar. = subjectid;
 ods select FitStatistics;
run; quit;
%mend cv;


%cv ( weight );
%cv ( momwtgain );
%cv ( cigsperday );


*Would like a table that looks something like this;
data want; 
 length Name $20.;
 input Name $ CV RMSE;
cards;
Weight 23.43 851.41
MomWtGain -141.24 9.89
CigsPerDay 229.13 0.38
;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Here's some instructions and explanations on how to capture output that is shown.
https://blogs.sas.com/content/sastraining/2017/03/31/capturing-output-from-any-procedure-with-an-ods...

 

Table Names for PROC GLM are here, I think you want FitStatistics

https://documentation.sas.com/?docsetId=statug&docsetTarget=statug_glm_details70.htm&docsetVersion=1...

 

Add the following before your proc, you'll probably want to modify your macro so that the output has a unique name.

ods output fitstatistics = want;

@bkq32 wrote:

I'm calculating CV and RMSE for several variables and would like to output the PROC GLM results to a SAS table. Is there a way to do this?

 

*Create sample data with repeat measures;
data have ( keep = subjectid weight momwtgain cigsperday );
 format subjectid;
 set sashelp.bweight;
 if _N_ <= 6;
 subjectid = _N_;
 if _N_ = 2 then subjectid = 1;
 if _N_ in ( 3, 4 ) then subjectid = 2;
 if _N_ in ( 5, 6 ) then subjectid = 3;
 if _N_ = 1 then cigsperday = 1;
run;


*Calculate CV and RMSE;
%macro cv ( covar );
proc glm data = have;
 model &covar. = subjectid;
 ods select FitStatistics;
run; quit;
%mend cv;


%cv ( weight );
%cv ( momwtgain );
%cv ( cigsperday );


*Would like a table that looks something like this;
data want; 
 length Name $20.;
 input Name $ CV RMSE;
cards;
Weight 23.43 851.41
MomWtGain -141.24 9.89
CigsPerDay 229.13 0.38
;
run;

 

View solution in original post

3 REPLIES 3
Reeza
Super User

Here's some instructions and explanations on how to capture output that is shown.
https://blogs.sas.com/content/sastraining/2017/03/31/capturing-output-from-any-procedure-with-an-ods...

 

Table Names for PROC GLM are here, I think you want FitStatistics

https://documentation.sas.com/?docsetId=statug&docsetTarget=statug_glm_details70.htm&docsetVersion=1...

 

Add the following before your proc, you'll probably want to modify your macro so that the output has a unique name.

ods output fitstatistics = want;

@bkq32 wrote:

I'm calculating CV and RMSE for several variables and would like to output the PROC GLM results to a SAS table. Is there a way to do this?

 

*Create sample data with repeat measures;
data have ( keep = subjectid weight momwtgain cigsperday );
 format subjectid;
 set sashelp.bweight;
 if _N_ <= 6;
 subjectid = _N_;
 if _N_ = 2 then subjectid = 1;
 if _N_ in ( 3, 4 ) then subjectid = 2;
 if _N_ in ( 5, 6 ) then subjectid = 3;
 if _N_ = 1 then cigsperday = 1;
run;


*Calculate CV and RMSE;
%macro cv ( covar );
proc glm data = have;
 model &covar. = subjectid;
 ods select FitStatistics;
run; quit;
%mend cv;


%cv ( weight );
%cv ( momwtgain );
%cv ( cigsperday );


*Would like a table that looks something like this;
data want; 
 length Name $20.;
 input Name $ CV RMSE;
cards;
Weight 23.43 851.41
MomWtGain -141.24 9.89
CigsPerDay 229.13 0.38
;
run;

 

Reeza
Super User
Or try the PERSIST option on the ODS OUTPUT statement, not sure if that would work here.
bkq32
Quartz | Level 8

Thank you! I ended up doing the following:

 

%macro cv ( covar );
ods output fitstatistics = x_&covar.;


proc glm data = have;
 model &covar. = subjectid;
 ods select FitStatistics;
run; quit;
%mend cv;


%cv ( weight );
%cv ( momwtgain );
%cv ( cigsperday );


data want;
 set x_:;
run;

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 1251 views
  • 2 likes
  • 2 in conversation