首页 > 解决方案 > 如何在宏参数中传递一系列数值?

问题描述

我正在尝试编写一个仅在作为参数传递时才显示年龄从 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

   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 时会出错。

任何帮助表示赞赏!

PS这里是初学者!

标签: macrossas

解决方案


为什么不让调用者传入逻辑呢?

where (int(yrdif(Birthday,today(),'ACTUAL')) &p_age)
...
%detReport( p_age =between 20 and 40)
%detReport( p_age = >= 40)

推荐阅读