我正在SAS中学习proc sql。当我使用sql sum函数时,我意识到如果添加了比较运算符,则输出为行数而不是垂直和。我如何获得垂直总和?所说总和的背后机制是什么?
def iterPower (base, exp):
"""Run a program in which the base multiplies itself by the exponent value"""
exp = 3
for n in base(exp):
exp *= base
return exp
base = 5
exp = 3
print(iterPower(5,3))
预期结果将为3 + 5 = 8;
实际结果是2
答案 0 :(得分:2)
proc sql;
select sum(target)
from apple
where target ge 3;
quit;
我相信您的代码正在将(目标gt 3)作为布尔表达式进行评估,因此,由于在SAS TRUE = 1和FALSE = 0中,求和函数的总和为0,0,1,1。
答案 1 :(得分:1)
Craig的解决方案实际上更好,但是如果在其他情况下结束,您可以尝试做。
proc sql;
select sum(case when target ge 3 then target else 0 end)
from apple;
quit;