Hello,
Make by_var a keyword parameter :
%macro regress(input,dep, indep, cluster_var, FE, modelNo, by_var=);
*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;
%if &by_var. ne %then %do;
by &by_var;
%end;
%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;
Note, in the macro signature, how by_var is now after the positional parameters and is followed by "=".
You can now call the macro with or without giving a value for this parameter :
%regress(input1,dep1, indep1, cluster_var1, 1, model1);
%regress(input1,dep1, indep1, cluster_var1, 1, model1, by_var=var1);
In the first call, the by statement will be ignored as the condition "&by_var. ne " will be false.
... View more