楼主: dxystata
1544 2

如何判定顺序为真? [推广有奖]

版主

大师

34%

还不是VIP/贵宾

-

TA的文库  其他...

Software

中英文Ebook

R学习

威望
2
论坛币
182304 个
通用积分
15205.6031
学术水平
208 点
热心指数
271 点
信用等级
174 点
经验
291157 点
帖子
5375
精华
1
在线时间
13478 小时
注册时间
2006-6-21
最后登录
2024-4-26

初级学术勋章 初级热心勋章 中级热心勋章 初级信用勋章

20论坛币
%let values=1 2;%let values=A B;
如果&value顺序为从小到大,则为真,否则为假?谢谢!



关键词:values value alue 从小到大 let values 如何

本帖被以下文库推荐

沙发
sniperhgy 发表于 2014-11-20 15:34:32 |只看作者 |坛友微信交流群
楼主你好,假定values里面都是用空格作为分隔符好的,请试试如下代码:
  1. %let values=1 2 2.1 3;

  2. %macro CheckOrder(Var);
  3.   %let var_count=%sysfunc(countw("&&&var.", " "));
  4.   %let true_count=0;
  5.   %put &var_count.;
  6.   %do i = 1 %to (&var_count. - 1);
  7.     %if %scan(&&&var., (&i. + 1), %str( )) > %scan(&&&var., &i., %str( )) %then
  8.       %let true_count=%eval(&true_count. + 1);
  9.   %end;
  10.   %if &true_count. = (&var_count. - 1) %then
  11.     %put True;
  12.   %else
  13.     %put False;
  14. %mend;

  15. %CheckOrder(values)
复制代码
已有 1 人评分论坛币 学术水平 热心指数 收起 理由
crystal8832 + 12 + 1 + 1 热心帮助其他会员

总评分: 论坛币 + 12  学术水平 + 1  热心指数 + 1   查看全部评分

使用道具

藤椅
farmman60 发表于 2014-11-21 05:35:29 |只看作者 |坛友微信交流群
  1. %macro test(string);
  2.      %let i=1;
  3.      %do %while (%scan(&string,&i,%str( )) ne);
  4.             %let val1=%scan(&string,&i,%str( ));
  5.         %let val2=%scan(&string,(&i+1),%str( ));   
  6.         %if &val2 eq  %then %goto leave;
  7.         %else %if &val1>&val2 %then %goto label;
  8.                 %let i=%eval(&i+1);
  9.      %end;
  10.      %leave:  %put "Values of string are ordered from the smallest to largest" ;
  11.      %goto last;
  12.          %label:  %put "Values of string are not ordered from the smallest to largest";
  13.          %last:
  14. %mend;

  15. %test(%str(a c d d e ))
  16. %test(%str(a b d c f))
  17. %test(%str(3 3 4 8 9 9))
  18. %test(%str(. 4 7 . 10))
复制代码

使用道具

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

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-27 04:13