BookmarkSubscribeRSS Feed
fafrin420
Fluorite | Level 6

 

 

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;

 

8 REPLIES 8
Reeza
Super User

Can you show the code that works for comparison?

 

 

PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
ballardw
Super User

@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.

Reeza
Super User
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. 

PaigeMiller
Diamond | Level 26

@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.

--
Paige Miller
PGStats
Opal | Level 21

@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.

PG
PaigeMiller
Diamond | Level 26

@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.

--
Paige Miller
Reeza
Super User

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;

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!

What is ANOVA?

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.

Discussion stats
  • 8 replies
  • 3331 views
  • 17 likes
  • 5 in conversation