sum和+之间的区别? [英] sas difference between sum and +?

查看:39
本文介绍了sum和+之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

data whatever;
 infile '';
 input price cost;
 <statement>;
run;

中,使用total = sum(total,cost)total = total + cost有什么区别?

In <statement>, what's the difference between using total = sum(total,cost) and total = total + cost ?

推荐答案

区别如下:

如果你想计算累计总数,你应该使用 sum 语句.

If you want to calculate cumulative total , you should use sum statement.

total = sum(total,cost)/* 它是一个求和函数 */

total = sum(total,cost) /* its a sum function */

total+cost/* 求和语句,形式为变量+表达式*/

total+cost /* its a sum statement,the form is variable+expression */

这里:

total"指定累加器变量的名称,其中包含一个数值.

"total" specifies the name of the accumulator variable, which contains a numeric value.

1) 在 SAS 读取第一个观测值之前,变量(在这种情况下为总计)自动设置为 0.变量的值从一个迭代保留到下一个迭代,就好像它出现在 RETAIN 语句中一样.

1) The variable(total in this case) is automatically set to 0 before SAS reads the first observation. The variable's value is retained from one iteration to the next, as if it had appeared in a RETAIN statement.

2) 要将 sum 变量初始化为 0 以外的值,请将其包含在具有初始值的 RETAIN 语句中.

2) To initialize a sum variable to a value other than 0, include it in a RETAIN statement with an initial value.

成本"是一个表达式

1) 计算表达式并将结果添加到累加器变量中.

1) The expression is evaluated and the result added to the accumulator variable.

2) SAS 将产生缺失值的表达式视为零.

2) SAS treats an expression that produces a missing value as zero.

sum 语句与 sum 函数的不同之处在于 sum 语句保留了它之前计算的值.

A sum statement is differ from a sum function in a way that a sum statement retains the value which it has calculated earlier.

然而,sum 语句相当于使用 SUM 函数和 RETAIN 语句,如下所示:

However, The sum statement is equivalent to using the SUM function and the RETAIN statement, as shown here:

retain total 0;
total=sum(total,cost);

这篇关于sum和+之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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