Search code examples
spss

I want to sum using IF condition in SPSS


I am looking for sum if syntax in SPSS. I have 3 variable. UUID is repeted here. I want to sum the server count for each UUID (ex:68d92 )and Virt flag P. I want syntax in SPSS. How can I do this?

server_conunt    `UUID`           `virt_flag` `P count (excel formula)`                                  ANswer
 1                68d92               P         '=SUMIFS([server_count],[uuid],[@uuid],[virt_flag],"P")  13
 1                68d92               P
 1                68d92              HP
 6                68d92              P
 1                68d92              P
 1                68d92              Hp
 1                68d92               P
 1                68d92               P 

 1                af8b1              P                                                                        7 
 1                af8b1              Hp 
 2                af8b1              P
 1                af8b1              Hp
 1                af8b1              P

Solution

  • Use a temporary SELECT IF for the condition and AGGREGATE to get the counts in either a new dataset or attached to each case. For example, to append to existing cases,

    temporary.
    select if virt_flag eq 'P'.
    aggregate /outfile=* mode=addvariables
     /break UUID
     /sum_server_conunt = sum(server_conunt).