+ Reply to Thread
Results 1 to 3 of 3

Thread: syntax: number of occurence of a times b

Hybrid View

  1. #1
    Points: 946, Level: 16
    Level completed: 46%, Points required for next Level: 54

    Location
    Vienna, Austria, Europe
    Posts
    50
    Thanks
    1
    Thanked 8 Times in 7 Posts

    syntax: number of occurence of a times b

    I have 5 variables var1 to var5 that have either 1, 2 or 3 as value. i want to compute a kind of index that is represented by this formula:

    index = (number of 1's in var1 to var5)*2 + (number of of 2's in var1 to var5)

    Neither COMPUTE nor COUNT lead me to success.
    Please be gracious in judging my english. (I am not a native speaker/writer.)

  2. #2
    Points: 946, Level: 16
    Level completed: 46%, Points required for next Level: 54

    Location
    Vienna, Austria, Europe
    Posts
    50
    Thanks
    1
    Thanked 8 Times in 7 Posts

    Re: syntax: number of occurence of a times b

    Found a solution by myself and leaving it here if anybody needs the same thing sometime:
    Code: 
    COMPUTE myindex= 0.
    DO REPEAT v=var1 TO var5.
       DO IF v=1.
          COMPUTE myindex= myindex+2.
       END IF.
       DO IF v=2.
          COMPUTE myindex= myindex+1.
       END IF.
    END REPEAT.
    Please be gracious in judging my english. (I am not a native speaker/writer.)

  3. #3
    Points: 1,494, Level: 21
    Level completed: 94%, Points required for next Level: 6

    Posts
    70
    Thanks
    0
    Thanked 27 Times in 25 Posts

    Re: syntax: number of occurence of a times b

    Just for your future reference, the count command is used in the following way:

    Code: 
    count #a = var1 to var5 (1).
    count #b = var1 to var5 (2).
    compute myindex = (#a*2) + #b.
    exe.

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts








Advertise on Talk Stats