多个变量的多个条件

时间:2017-09-14 10:39:50

标签: sas

我真的很想得到一些我想写的sas程序的帮助

我有五个变量可以选择兴趣或奖励 叫他们wo1 wo2 wo3 wo4 wo5

有没有办法做一个if语句,检查所有五个值的"兴趣"然后生成一个计算变量,其中包含变量的总数,其中包含的数值为wo1amt wo2amt wo3mt等。

且没有感兴趣的值的值返回0。

或者我是否需要为每个语句创建一个if语句,为每个语句创建一个calc var然后将它们与另一个一起求和?

任何帮助,方向都将非常感激......

2 个答案:

答案 0 :(得分:0)

如果我理解正确,看起来你需要多个if语句。

您可以初始化一个总变量,然后为每个贡献变量添加它,如下所示:

total = 0;
if wo1 = 'Interest' then total = total + wo1amt;
if wo2 = 'Interest' then total = total + wo2amt;
if wo3 = 'Interest' then total = total + wo3amt;
if wo4 = 'Interest' then total = total + wo4amt;
if wo5 = 'Interest' then total = total + wo5amt;

答案 1 :(得分:0)

Arrays可以很好地适应这种情况。

array wo(*) wo1-wo5;
array woamt(*) wo1amt wo2amt wo3amt wo4amt wo5amt;
total = 0;
do i = 1 to 5;
   total + woamt(i)*(wo(i)='Interest');
end;
相关问题