SPSS Statistics

SPSS Statistics

Your hub for statistical analysis, data management, and data documentation. Connect, learn, and share with your peers! 

 View Only
  • 1.  String values in do repeat

    Posted Wed June 16, 2021 12:39 PM
    I want to compare the value of a variable against a list of string values. The strings are UK postcodes, of this format: "E1 1DT". If I include a value like this "E1 1EE" SPSS tries to treat the 1EE part as an exponential number, and gives an error message, even though the string is in quotes.
    Here is a short syntax:
    string pcc (a8).
    compute pcd=0.
    do repeat pcc="E1 1DT", "E1 1DU", "E1 1DW", "E1 1EE", "E1 1EG".
    if (postcodecopy eq pcc) pcd=1.
    end repeat.
    execute.

    This is the error message: 
    >Warning # 203 in column 63. Text: 1E
    >An 'E', beginning the exponent portion of a number, was not followed by any
    >digits.
    >The symbol will be treated as an invalid special character.

    It ends with this:
    >Error # 4001. Command name: end repeat
    >An END REPEAT command has appeared without a previous DO REPEAT command.
    >Execution of this command stops.
    execute.

    Any suggestions?

    ------------------------------
    Charlie Owen
    ------------------------------

    #SPSSStatistics


  • 2.  RE: String values in do repeat

    Posted Wed June 16, 2021 01:11 PM
    I don't get this error running that code.  Is it possible that your input variable, pcc, is declared as  numeric, and the error is coming from those values?

    The pcc declaration is unnecessary as the pcc index variable will just take the listed values.

    But this code could be written more simply as this
    compute pcd = any(postcodecopy, "E1 1DT", "E1 1DU", "E1 1DW", "E1 1EE", "E1 1EG").

    If none of this clears things up, could you send me a small sample of the data as a sav file (jkpeck@gmail.com)?

    --





  • 3.  RE: String values in do repeat

    Posted Thu June 17, 2021 01:17 PM
    Thanks for looking at this for me, John. I had thought of the compute/any route, but I was worried my list was too long - over 1,000 items!

    Your reply spurred me to pare down the syntax, and eventually it became clear that the problem is the quote marks: I used Word to insert these around the items in my list. As you probably know, Word uses 'intelligent' quotes - i.e. puts a different character before and after the quoted item - but SPSS does not recognise these as quotes. If I change these to 'unintelligent' quotes, then both our methods work.

    Charlie Owen.
    -----------------------------------------------------------------------------------------
    Thomas Coram Research Unit
    UCL Social Research Institute
    27 Woburn Square  London  WC1H 0AA 
    Tel: 020 7612 6942

    ------------------------------------------------------------------------------------------






  • 4.  RE: String values in do repeat

    Posted Thu June 17, 2021 03:14 PM
    Glad that worked.  You can turn off that Word autocorrection for the quote type.  It's interesting that in your post, the quotes were back to the regular type.

    If you have your postcodes in a dataset, you can use the SPSSINC TRANS extension command to look these up.  If the lookup fails, you get a missing value.

    Here is an example from the help comments in the extendedTransforms.py module shipped with Statistics.

    * The lookup table.
    data list free/ value(F8.0) akey(A1).
    begin data
    10 'a'
    20 'b'
    100 'z'
    end data.
    dataset name lookup.

    * The main dataset.
    data list free/x(f8.0) y(A2).
    begin data
    1 'a'
    2 'b'
    5 'a '
    10 ''
    1 'b'
    end data.
    dataset name main.
    dataset activate main.

    spssinc trans result = resultcodealpha
    /initial "extendedTransforms.vlookup('akey', 'value', 'lookup')"
    /formula func(y).

    --