• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

循环遍历SPSS的项目和求和项目

用户头像
it1352
帮助1

问题说明

我有两组变量,称为 ITEM 1 到 ITEM 47,另一组称为 L1 到 L47.我想要做的是计算 Ls 的总和,如果有任何 ITEM#i=1.我写的内容如下:

I have two sets of variables called ITEM 1 to ITEM 47, and another called L1 to L47. What I want to do is to calculate the sum of Ls if any ITEM#i=1. What I wrote is as following:

计算 LSUM=0.环形#i=1 到 47.
IF (ITEM(#i)=1) LSUM=LSUM L(#i).结束循环.

COMPUTE LSUM=0. LOOP #i=1 to 47.
IF (ITEM(#i)=1) LSUM=LSUM L(#i). END LOOP.

但我收到一条错误消息,指出这些字符与任何现有函数或向量都不匹配.那我该怎么办?您的意见将不胜感激.

But I got an error message saying the characters do not match any existing function or vector. What should I do then? Your inputs will be very appreciated.

谢谢.

真诚的,露西

正确答案

#1
COMPUTE LSUM=0.
exe.

vector vitems = ITEM 1 to ITEM 47.
vector vl = L1 to L47.

LOOP #vecid = 1 to 47.
do IF (  vitems(#vecid) eq 1 and not missing(vl(#vecid))  ).
compute LSUM=LSUM vl(#vecid).
end if.
END LOOP.
exe.

参见 SPSS 中的 VECTOR 命令.您不能只创建循环并将变量视为数组.它们必须首先被放入向量中.另外,请检查 COMPUTE 命令.我认为 SUM 会更合适,因为如果你写计算 v1 = v2 v3"并且 v2 有数据但 v3 是空的,v1 将是空的.

See the VECTOR command in SPSS. You can not just create loop and treat variables as in array. They must first be put into vectors. Also, check the COMPUTE command. I think SUM would be more appropriate because if you write " compute v1 = v2 v3 " and v2 has data but v3 is blank, v1 will be blank.

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhcfeibg
系列文章
更多 icon
同类精品
更多 icon
继续加载