How about this code?
%macro final (title=
, state =
, age =
, tran_year =
, var =
, sumvar =
);
data profile3;
%if &var ne %then %do; /* I don't know if you need retain, but you can use empty parameters to make it work. */
retain &var;
%end;
set profile2;
if tran_year ne .;
where %if &age ne %then %do;
age &age
%end;%else
%do;
age > 0
%end;
%if &Tran_Year ne %then %do;
and Tran_Year = &tran_year
%end;
%if &State ne %then %do;
and (State in ("%sysfunc(TRANWRD(&state,%str(,)," "))"))
%end;
;
keep acct_ID Name Age Balance Last_Tran_Date tran_year;
run;
%if &title = %then %do;
%let title=Detail Listing of Account;
%end;
%if &State = %then %do;
%let State=All;
%end;
%if &age = %then %do;
%let age=All;
%end;
%if &Tran_Year = %then %do;
%let tran_year=All;
%end;
ods rtf file = "/folders/myfolders/macro.rtf";
proc sort data = profile3 out = profile4;
by tran_year;
run;
proc print data = profile4 noobs sumlabel= "Total Balance" grandtotal_label= "Grand Total" width=uniformby;
by tran_year;
%if %upcase(&sumvar)^=NO %then %do;
sum balance; *need macro for total balance var &var;
%end;
title2 j=l "Title: &title" j=r "Run date: %sysfunc(date(),worddate.)";
title3 j=l "State: &state" j=c "Age: &age" j=r "Tran Year: &tran_year";
run;
ods rtf close;
%mend final;
/* 2 sample patterns */
%final (title=Detail Listing of Account
,state =CA%str(,)NY
,age=%str(<=)40
,tran_year = 2016
,var=Acct_ID Name Age Balance Last_Tran_Date
,sumvar=yes
);
%final (title=Detail Listing of Account
,state =
,age=
,tran_year =
,var=
,sumvar=
);
... View more