楼主: Tigflanker
1542 3

问一个很小的%if问题 [推广有奖]

  • 8关注
  • 18粉丝

副教授

49%

还不是VIP/贵宾

-

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

楼主
Tigflanker 发表于 2013-3-17 15:04:37 |AI写论文
20论坛币
%macro a;
%let a=2;%let b=-2;%let c=-2.38050453744706;
%if &a>0 %then %put &a;
%if &b>0 %then %put &b;
%if &c>0 %then %put &c;
%mend;
%a;

如上程序,请问,为什么 c 没有被put出来?谢谢

********补充**************8;

我自己有个解决方案,钻了个空子:
%macro a;
%let a=2;%let b=-2;%let c=-2.38050453744706;
%if &a>0 %then %put &a;
%if &b>0 %then %put &b;
%if %substr(&c,1,2)>0 %then %put &c;   *这样就不报错了;
%mend;
%a;

最佳答案

bobguy 查看完整内容

SAS implicitly uses %eval function to do a comparison in SAS macro language. This is correct when all elements are inters. Otherwise one needs to use %syaevalf if any of them is a floating number. %macro a; %let a=1;%let b=-2;%let c=2.38050453744706; %if %sysevalf(&a>0) %then %put &a; %if %sysevalf(&b>0) %then %put &b; %if %sysevalf(&c>0) %then %put &c; %mend; %a;
关键词:SUBSTR Macro Then subs 解决方案

回帖推荐

farmman60 发表于4楼  查看完整内容

%macro a; %let a=2;%let b=-2;%let c=-2.38050453744706; %if &a>0 %then %put &a; %if &b>0 %then %put &b; %if %sysevalf(&c,boolean)>0 %then %put &c; /*Use %SYSEVALF(expression)*/ %mend; %a;
Bye SAS.
若有缘,能重聚。

沙发
bobguy 发表于 2013-3-17 15:04:38
SAS  implicitly uses %eval function to do a comparison in SAS macro language. This is correct when all elements are inters. Otherwise one needs to use %syaevalf if any of them is a floating number.


%macro a;
%let a=1;%let b=-2;%let c=2.38050453744706;
%if %sysevalf(&a>0) %then %put &a;
%if %sysevalf(&b>0) %then %put &b;
%if %sysevalf(&c>0) %then %put &c;
%mend;
%a;
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
a6566792 + 1 + 1 + 1 正解

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

藤椅
webgu 发表于 2013-3-17 15:29:12
C=-2.38050453744706 ,小于0,为什么会PUT 出来?
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
Tigflanker + 1 + 1 + 1 嘿嘿,运行下,会报错的。

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

SAS资源
1. SAS 微信:StatsThinking
2. SAS QQ群:348941365

板凳
farmman60 发表于 2013-3-17 22:16:38

%macro a;
%let a=2;%let b=-2;%let c=-2.38050453744706;
%if &a>0 %then %put &a;
%if &b>0 %then %put &b;
%if %sysevalf(&c,boolean)>0 %then %put &c;   /*Use %SYSEVALF(expression<, conversion-type>)*/
%mend;
%a;
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
Tigflanker + 1 + 1 + 1 新了解的参数

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

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

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