In the following code, my dependent variables are Age, Height and Weight. My only one independent variable is Gender. I want to run the regressions by id and then store the estimates of the regressions (with different dependent variables) in one file.
The following code works except that for some of the ids, DF is 0 and the estimates are also 0. When I run the regressions without a loop, for each dependent variable separately (with the same dataset), DF is never 1. Can you help me saying what is wrong with my code?
proc sort data = DataSET out= DataSET;
by id;
run;
%let dvar = Age Height Weight;
%let N = %sysfunc(countw(&dvar));
%macro reg; /* macro to create regression estimates in one table */
proc datasets nolist lib=work;
delete Merged Each_var;
run;
proc sort data=DataSET; by id; run;
%do i=1 %to &N;
%let var = %scan(&dvar, &i);
ods exclude all;
ods output ParameterEstimates = Each_&var;
proc reg data = DataSET;
by id;
model &dvar = Gender; run;
proc datasets lib=work;
append base=Merged data=Each_&var FORCE; run;
%end;
%mend;
%reg;
Can you show the code that works for comparison?
Honestly why even use a macro here at all? PROC REG can handle multiple dependent variables and output the results to a single data set in one run of PROC REG. I think you are making your life difficult by using macros.
@PaigeMiller wrote:
Honestly why even use a macro here at all? PROC REG can handle multiple dependent variables and output the results to a single data set in one run of PROC REG. I think you are making your life difficult by using macros.
And use the Label: option on the model statement to make the results easier to use/read.
ods exclude all;
ods output parameterEstimates = want;
proc reg data=sashelp.class;
model weight height = age;
run;
The model statement can hold multiple variables as well.
My only concern with doing this is if you have missing data and want to selectively include records. If you have no missing data this is not an issue.
@Reeza wrote:
The model statement can hold multiple variables as well.
My only concern with doing this is if you have missing data and want to selectively include records. If you have no missing data this is not an issue.
This is probably the original problem, due to miscoding.
@Reeza, @PaigeMiller, proc glm goes into "MANOVA mode" only if you specify option MANOVA in the proc statement or use a MANOVA statement. Otherwise, the procedure analyses each dependent variable using all available data.
@PGStats wrote:
@Reeza, @PaigeMiller, proc glm goes into "MANOVA mode" only if you specify option MANOVA in the proc statement or use a MANOVA statement. Otherwise, the procedure analyses each dependent variable using all available data.
@PGStats, this user was using PROC REG. What does PROC REG do? I suspect if any Y is missing, then the observation isn't used, most likely the original problem due to miscoding.
Tested this, PROC GLM does include all data when available, where PROC REG excludes any row with missing data.
So PROC GLM will avoid that issue entirely, which is good to know! Thanks @PGStats
title 'Two at once';
proc glm data=class;
model weight height = age;
run;
title 'Weight regression';
ods output parameterestimates;
proc glm data=class;
model weight = age;
run;
title 'Height regression';
ods output parameterestimates;
proc glm data=class;
model height = age;
run;
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.