楼主: 木叶知秋
4408 6

宏里面的in操作符 [推广有奖]

  • 0关注
  • 2粉丝

博士生

10%

还不是VIP/贵宾

-

威望
0
论坛币
1237 个
通用积分
0.0002
学术水平
29 点
热心指数
30 点
信用等级
31 点
经验
3622 点
帖子
110
精华
0
在线时间
304 小时
注册时间
2009-3-29
最后登录
2023-9-8

楼主
木叶知秋 发表于 2016-7-8 15:21:40 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
  1. %macro sample_select(month);
  2. %if %sysfunc(mod(&month.,100)) in (1 3 5 7 8 10 12) %then %let end=31;
  3. %if %sysfunc(mod(&month.,100)) in (4 6 9 11) %then %let end=30;
  4. %if %sysfunc(mod(&month.,100))=2 %then %let end=28;
  5. %put &end.;
  6. %mend;
  7. %sample_select(201503);
复制代码
宏的%if语句中使用in操作符会报“需要的操作符在以下表达式中没有找到”错误,请问如何修改?谢谢

二维码

扫码加我 拉你入群

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

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

关键词:操作符 sysfunc Select Sample month 表达式 如何

沙发
johyw 发表于 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)
已有 1 人评分论坛币 学术水平 热心指数 信用等级 收起 理由
木叶知秋 + 5 + 2 + 2 + 2 精彩帖子

总评分: 论坛币 + 5  学术水平 + 2  热心指数 + 2  信用等级 + 2   查看全部评分

藤椅
smilealways193 发表于 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问题还是得用英文来搜索啊

7
johyw 发表于 2016-7-13 03:20:40
看起来google在这方便是比baidu好一点?

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-2-3 01:02