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;
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
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;
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
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;
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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.
Ready to level-up your skills? Choose your own adventure.