Compute sum of all cases

2019-07-11 20:16发布

问题:

browser pageviews   month   totalhits percentage
-------------------------------------------------
ch     227025   Nov 2012    626760      36.22
ie     184232   Nov 2012    626760      29.39
s       81430   Nov 2012    626760      12.99
ff      72140   Nov 2012    626760      11.51
ie      39856   Nov 2012    626760      06.36
o        1010   Nov 2012    626760      00.16
rm        325   Nov 2012    626760      00.05
ot      20742   Nov 2012    626760      03.31

I have the above dataset. I want to calculate the percentage based on total hits. However, I want to calculate total hits based on the sum of pageviews. How can I sum multiple cases?

In excell it would be something like SUM(pageviews).

回答1:

See the AGGREGATE command. Example below:

data list free /browser (A2) pageviews (F6.0)  month (A3) year (A4) totalhits (F6.0) percentage (F4.2).
begin data
ch     227025   Nov 2012    626760      36.22
ie     184232   Nov 2012    626760      29.39
s       81430   Nov 2012    626760      12.99
ff      72140   Nov 2012    626760      11.51
ie      39856   Nov 2012    626760      06.36
o        1010   Nov 2012    626760      00.16
rm        325   Nov 2012    626760      00.05
ot      20742   Nov 2012    626760      03.31
end data.

compute const = 1.
AGGREGATE
  /OUTFILE=*
  MODE=ADDVARIABLES
  /BREAK=const
  /pageviews_sum = SUM(pageviews).
list vars = pageviews totalhits pageviews_sum.

Which returns in the output:

pageviews totalhits pageviews_sum

  227025    626760     626760.0
  184232    626760     626760.0
   81430    626760     626760.0
   72140    626760     626760.0
   39856    626760     626760.0
    1010    626760     626760.0
     325    626760     626760.0
   20742    626760     626760.0


标签: spss