循环遍历SPSS的项目和求和项目
问题说明
我有两组变量,称为 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.
谢谢.
真诚的,露西
正确答案
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
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
检查邮件是否发送成功
it1352 07-25 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
Android微调工具-删除当前选择
it1352 06-20 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20 -
希伯来语的空格句子标记化错误
it1352 06-22