Macros 如何在宏参数中传递一系列数值?
我正在尝试编写一个宏,仅当它作为参数传递时,才显示20-40或>=30的年龄 代码如下所示:Macros 如何在宏参数中传递一系列数值?,macros,sas,Macros,Sas,我正在尝试编写一个宏,仅当它作为参数传递时,才显示20-40或>=30的年龄 代码如下所示: %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 fr
%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)
该代码在传递单个值(如>=30)时有效,但在传递20-40时给出错误
感谢您的帮助
这里是初学者 为什么不让调用方传入逻辑
where (int(yrdif(Birthday,today(),'ACTUAL')) &p_age)
...
%detReport( p_age =between 20 and 40)
%detReport( p_age = >= 40)
为什么不让调用方传入逻辑
where (int(yrdif(Birthday,today(),'ACTUAL')) &p_age)
...
%detReport( p_age =between 20 and 40)
%detReport( p_age = >= 40)
如果遵循@Tom advice,宏还可以在标题或脚注中使用criteria参数。即
footnote1“年龄标准:&p_年龄”代码>如果遵循@Tom advice,宏还可以在标题或脚注中使用criteria参数。即footnote1“年龄标准:&p_年龄”代码>我尝试过,但%detreport(p_age=20到40)给出了一个错误。单个值正在工作您是否更改了宏使用参数值的方式?我尝试过,但%detreport(p_age=20到40)给出了一个错误。单个值正在工作您是否更改了宏使用参数值的方式?