Reputation: 9
I am trying to write a macro that display age from 20-40 or >=30 only when it is passed as a parameter.
The code looks like:
%macro detReport(p_age=);
proc sql;
create table detail as
select acct_id,
name format=$20. ,
int(yrdif(Birthday,today(),'ACTUAL')) as Age,
balance,
state,
last_Tran_date
from profile
%if &p_age ne "" %then %do;
%if %index(&p_age,-) > 0 %then %do;
where int(yrdif(Birthday,today(),'ACTUAL')) between (%scan(&p_age,1,"-") and
%scan(&p_age,2,"-"))
%end;
%end;
%else %do;
where (int(yrdif(Birthday,today(),'ACTUAL')) &p_age);
%end;
quit;
proc print data =detail ;
run;
%mend detReport;
%detReport( p_age =20-40)
The code works when a single value is passed (like >=30) but gives error when 20-40 is passed.
Any help is appreciated!
P.S A beginner here!
Upvotes: 0
Views: 191
Reputation: 51566
Why not just let the caller pass in the logic?
where (int(yrdif(Birthday,today(),'ACTUAL')) &p_age)
...
%detReport( p_age =between 20 and 40)
%detReport( p_age = >= 40)
Upvotes: 2