Compute sum of all cases

痴心易碎 提交于 2019-12-24 02:23:54

问题


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


来源:https://stackoverflow.com/questions/15345941/compute-sum-of-all-cases

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