if-statement - 如何将 &&var&i 放入 if 条件
问题描述
/*create macro variables*/
PROC SQL NOPRINT;
SELECT RESTRICTIONS
INTO :RESTRI1 - :RESTRI35
FROM SASDATA.RESTRICTIONLIST;
QUIT;
%PUT &RESTRI2;
/*the resolved value is: */
gender = 'M' and state = 'CA'
sasdata.newlist&i
当第 i 个限制为&&restri&i
(例如:gender = 'M'
和state = 'CA'
)时,我想创建一个数据集。&&restri&I*
我只想要在这个新创建的数据集中满足限制的观察
虽然 sasdata.newlist2 包含 sasdata.oldlist 中的所有数据,但 if 条件不起作用。有人可以帮我解决这个问题吗?
%Macro testing(I);
data sasdata.newlist&i;
set sasdata.oldlist;
%if &&restri&i %then;
run;
%mend testing;
%testing(2)
解决方案
您没有在适当的上下文中解析宏变量。应用限制代码时,解决它,以便可以将其编译(数据逐步)作为 DATA 步的一部分。
%Macro testing(I);
data sasdata.newlist&i;
set sasdata.oldlist;
/* %if &&restri&i %then; NO-no-no, incorrect context */
* apply ith restriction as a sub-setting IF statement;
if &&restri&i;
run;
%mend testing;
%testing(2)
推荐阅读
- mongodb - $pull 文档中的多个对象 - MongoDB
- python - 找不到会话密钥...无法访问
- ios - 关闭如何删除视图控制器的内存?
- mongodb - 错误:当我启动和停止服务器时,MongoDB 不时为两个不同的数据库提供服务
- tomcat - 如何解决现场虚拟主机上tomcat默认页面的问题?
- lambda - 添加了 VPC 端点,但 Lambda 仍然超时
- jquery - 如果已加载值,如何在加载时清除文本框?
- java - 为地点消息和发件人显示“null”
- python - Python sys.stdin 和子进程 stdout 的区别
- javascript - 在 node.js 项目中找不到 .env 文件