macros - 如何在宏参数中传递一系列数值?
问题描述
我正在尝试编写一个仅在作为参数传递时才显示年龄从 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这里是初学者!
解决方案
为什么不让调用者传入逻辑呢?
where (int(yrdif(Birthday,today(),'ACTUAL')) &p_age)
...
%detReport( p_age =between 20 and 40)
%detReport( p_age = >= 40)
推荐阅读
- informatica-data-integration-hub - Informatica 之间的提取值
- android - Firebase 数据库设置值不会更改值
- java - 无法使用 Javal 11、Jetty 和 Jersey 将 HttpServletRequest 注入到 ContainerRequestFilter
- javascript - 如何使用谷歌表格中的应用脚本获取谷歌课堂作业数据
- php - Studio->getopt('send-errors') | WordPress
- amazon-web-services - 位置“默认”的备份存储无效
- javascript - 将表单数据解析为对象,然后推入数组
- apache-spark - 试图转换时间戳但得到模式 datetimeformatter 错误
- html - Flex Box 将项目居中而不是左对齐
- javascript - 地理位置更新频率取决于 Firefox 中的设备移动