Hi guys,
suppose to have the following piece of code:
%macro freq_for_value(data=, variable=, filter_value=);
%if &filter_value. ne %str() %then %do;
proc freq data=&data. (where=(&variable. = "&filter_value."));
tables &variable.;
title "Frequency for &variable. with value &filter_value.";
run;
%end;
%else %do;
proc freq data=&data.;
tables &variable.;
title "Frequency for all values of &variable.";
run;
%end;
%mend;
This macro basically performs proc freq in two different conditions: 1) if a variable takes a specific value and 2) if not.
I would like to run this macro but I have many lines of code after the first proc freq that I have to repeat (and that are identical) after the second proc freq like for example the following:
%macro freq_for_value(data=, variable=, filter_value=);
%if &filter_value. ne %str() %then %do;
proc freq data=&data. (where=(&variable. = "&filter_value."));
tables &variable.;
title "Frequency for &variable. with value &filter_value.";
run;
/*I add 10 rows of output formatting*/
............................................................................................
.............................................................................................
..............................................................................................
%end;
%else %do;
/* If no filter value, run PROC FREQ on the entire data set */
proc freq data=&data.;
tables &variable.;
title "Frequency for all values of &variable.";
run;
%end;
/*I add 10 rows of output formatting*/
............................................................................................
.............................................................................................
..............................................................................................
%mend;
Is there a way or a condition that could be declared at the beginning in order to prevent to repeat the coding after proc freq (output formatting) that would make the macro unnecessarily long and redundant? In other words I'm referring to something that, based on the fact that the variable can or not take a specified value, performs proc freq in a way or in the other one.
Thank you in advance