SPSS Syntax to add up values for all variables with the same prefix

╄→尐↘猪︶ㄣ 提交于 2019-12-11 02:27:49

问题


I am wondering if there is a way to have SPSS add up all variables that have the same prefix. For example, I have variables named MFQAP.1, MFQAP.2, MFQAP.3, etc. Is there a way to tell SPSS to add up all variables that begin with MFQAP.? I know I can tell SPSS to add up all variables from MFQAP.1 to MFQAP.n (where n is the highest number in the dataset). However, I am working with a dataset that will be continually updated, and the highest value for n may change. I do not want to have to always update my syntax. Any help is greatly appreciated!


回答1:


Use the following command to create a macro containing a comma separated list of the relevant variables:

spssinc select variables macroname="!MyVars"  
  /properties pattern="MFQAP.*"/options separator=", ".

You can now use the macro to calculate the sum like this:

compute MFQAPsum=sum(!MyVars).


来源:https://stackoverflow.com/questions/47913419/spss-syntax-to-add-up-values-for-all-variables-with-the-same-prefix

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!