问题
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