SAS 宏中的 if 语句 [英] If statement in SAS macro

查看:188
本文介绍了SAS 宏中的 if 语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

%macro pp();
data temp1;
 set dir.data
 call symput('prod', product); 
run;
%put "&prod";
%if prod = "&prod" %then %do;
   %put "&prod";
%end;
%mend;
%pp();

为什么 if 语句的计算结果为 false?

Why does the if statement evaluate to false?

推荐答案

在SAS宏语言中,一切都是字符串,所以你的语句

In the SAS macro language, everything is a character string, so your statement

%if prod = "&prod" %then %do;

永远不会是真的;字符串 prod 永远不会等于字符串 "&prod",因为一个字符串包含双引号而另一个不包含.

Will never be true; the string prod will never equal the string "&prod" if only because one string includes double-quotes and the other does not.

所以两边都使用双引号,或者根本不使用.这两者中的任何一个都会更好:

So use double-quotes on both sides or not at all. Either of these will be better:

%if "prod" = "&prod" %then %do;
%if  prod  =  &prod  %then %do;

另外,请注意,在此修复后,仅当您创建的宏变量具有 prod 的确切值(这四个字符)时,该语句才会为真".大小写很重要:prod 不等于 PROD.

Also, note that after this repair, the statement will be "true' only if the macro variable you created has the exact value of prod (those four characters). Case matters: prod is not equal to PROD.

这篇关于SAS 宏中的 if 语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆