全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
4409 6
2016-07-08
复制代码
宏的%if语句中使用in操作符会报“需要的操作符在以下表达式中没有找到”错误,请问如何修改?谢谢

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2016-7-9 06:01:38
加上这句话:options minoperator mindelimiter=',';

以下是官网的解释:
An IN operator is available for the macro language beginning in SAS® 9.2. The IN operator can be used in the %IF statement only when the MINOPERATOR option is set in the %MACRO statement or as a SAS® system option.

/* Prior to SAS 9.2, the following syntax was used */
%macro test(value);
   %if &value=1 or &value=2 or &value=3 or &value=4 or
       &value=5 or &value=6 %then %put Value found within list.;
   %else %put Value not in list.;
%mend;

%test(3)
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2016-7-11 08:55:39
是不是%in呀
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2016-7-11 09:46:28
johyw 发表于 2016-7-9 06:01
加上这句话:options minoperator mindelimiter=',';

以下是官网的解释:
非常感谢,我也搜了下,最全的解释如下:


This useful addition came in SAS 9.2 and I am amazed that it isn’t enabled by default. To do that you need to set the MINOPERATOR option unless someone has done it for you in the SAS AUTOEXEC or another configuration program. Thus, the safety first approach is have code like the following:

options minoperator;

%macro inop(x);

%if &x in (a b c) %then %do;
%put Value is included;
%end;
%else %do;
%put Value not included;
%end;

%mend inop;

%inop(a);

Also, the default delimiter is the space so if you need to change that, then the MINDELIMTER option needs setting. Adjusting the above code so that the delimiter now is the comma character gives us the following:

options minoperator mindelimiter=”,”;

%macro inop(x);

%if &x in (a,b,c) %then %do;
%put Value is included;
%end;
%else %do;
%put Value not included;
%end;

%mend inop;

%inop(a);

Without any of the above, the only approach is  to have the following and that is what we had to do for SAS versions prior to 9.2:

%macro inop(x);

%if &x=a or &x=b or &x=c %then %do;
%put Value is included;
%end;
%else %do;
%put Value not included;
%end;

%mend inop;

%inop(a);

It may be clunky but it does work and remains a fallback in newer versions of SAS. Saying that, having the IN operator available makes writing SAS Macro code that little bit swisher so it’s a good thing to know.
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2016-7-11 09:49:24
johyw 发表于 2016-7-9 06:01
加上这句话:options minoperator mindelimiter=',';

以下是官网的解释:
想探讨一下遇到这类问题的解决办法,怎么能搜到这些相关资料呢
我用中文搜索啥也没有,看了你的解释后,用英文搜options minoperator mindelimiter,结果答案全出来了。
看样子SAS问题还是得用英文来搜索啊
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2016-7-11 09:49:32
johyw 发表于 2016-7-9 06:01
加上这句话:options minoperator mindelimiter=',';

以下是官网的解释:
想探讨一下遇到这类问题的解决办法,怎么能搜到这些相关资料呢
我用中文搜索啥也没有,看了你的解释后,用英文搜options minoperator mindelimiter,结果答案全出来了。
看样子SAS问题还是得用英文来搜索啊
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群