楼主: Tigflanker
1257 3

[问答] 请问如何表示:&i. in (1 3 5 7) [推广有奖]

  • 8关注
  • 18粉丝

副教授

49%

还不是VIP/贵宾

-

威望
0
论坛币
2321 个
通用积分
9.9128
学术水平
179 点
热心指数
194 点
信用等级
167 点
经验
27443 点
帖子
622
精华
0
在线时间
851 小时
注册时间
2011-3-27
最后登录
2023-5-14

楼主
Tigflanker 发表于 2013-9-10 16:02:44 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
我有个很简单的问题想请问各位老师:

%macro a;
  %do i=1 %to 10;
    %if &i. in (1 3 5 7) %then ...;
  %end;
%mend a;

请问上面这个if应该如何表达?我不想使用四个排比句,除非不得已。谢谢。。

另外我记得%do i= 1,3,5,7 是不行的,当时有一个做法是:
%do i=1 %to 4;%let T&i.=%scan(1 3 5 7,&i.,' ');%end;
...
%if &i. = &&T&i..

现在不得已是这样做的,不知还有啥好点的办法么?谢谢。。。

二维码

扫码加我 拉你入群

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

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

关键词:Macro Then scan End Mac 如何

Bye SAS.
若有缘,能重聚。

沙发
yongyitian 发表于 2013-9-11 09:23:44
  1. %macro mymacro;
  2. %let p = 1 3 5 7;
  3. %do i=1 %to 10;
  4.      %if %sysfunc(indexw(&p, &i)) %then
  5.          %do;
  6.                %put AAA  &i;
  7.          %end;
  8.      %do j = 1 %to 4;
  9.          %if  &i = %scan(&p, &j, ' ') %then
  10.          %do;
  11.             %put BBB   &i;
  12.          %end;
  13.      %end;
  14. %end;
  15. %mend mymacro;
  16. %mymacro;
复制代码
From sas 9.2
Sample 35591: How to use the new macro IN operator for SAS 9.2

http://support.sas.com/kb/35/591.html
已有 2 人评分经验 论坛币 学术水平 热心指数 信用等级 收起 理由
Imasasor + 100 + 100 + 4 + 3 + 2 精彩帖子
Tigflanker + 1 + 1 + 1 正解,谢谢。

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

藤椅
yuerqieqie 发表于 2013-9-12 21:39:05
options minoperator; 这个option允许在macro中使用in operator。
%if %eval(&i in 1 3 5 7) %then %do;
        %put &i is in the list;
%end;
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
Tigflanker + 1 + 1 + 1 谢谢!9.2专属。。

总评分: 学术水平 + 1  热心指数 + 1  信用等级 + 1   查看全部评分

板凳
bobguy 发表于 2013-9-14 07:03:07
You can levelage the in function in sas9.3 as below.

141  %macro a;
142    %do i=1 %to 10;
143      %put i=&i in_return_value=%sysfunc(in(&i,1, 3, 5));
144    %end;
145  %mend a;
146  %a
i=1 in_return_value=1
i=2 in_return_value=0
i=3 in_return_value=1
i=4 in_return_value=0
i=5 in_return_value=1
i=6 in_return_value=0
i=7 in_return_value=0
i=8 in_return_value=0
i=9 in_return_value=0
i=10 in_return_value=0
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
Tigflanker + 1 + 1 + 1 Yes, it's really a good way. Thank you .

总评分: 学术水平 + 1  热心指数 + 1  信用等级 + 1   查看全部评分

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-22 13:14