I am trying to write a macro that runs regressions with or without BY variables. It is working if I specify the BY variables. But what if I dont have any BY variable and want to perform regressions on the whole sample? That is, if the parameter by_var is none, then ignore the BY statement. My code so far is: %macro regress(input,dep,indep,by_var,cluster_var,FE,modelNo);
*FE is time fixed effect;
data sample; set &input.;run;
ods output ParameterEstimates=para_est fitstatistics=fit;
proc surveyreg data=sample;
output out=fitted_&dep&modelNo.(keep=stock date predicted_value rename=(predicted_value=fitted&modelNo._&dep)) p= Predicted_value r=residual u=upper_bound l=lower_bound;
cluster &cluster_var;
by &by_var;
%if &FE.=1 %then %do;
class date;
model &dep = &indep date/solution;
%end;
%else %if &FE.=0 %then %do;
model &dep = &indep/solution;
%end;
run;
%mend;
... View more