SPSS Statistics

SPSS Statistics

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

 View Only
  • 1.  Using wildcards in the IF command together with a string variable

    Posted Fri July 28, 2023 10:54 AM

    Greetings,

    I'm creating a variable that categorizes email domains based on the substring contents of a string variable (Email_Domain) using an IF function. I'm using a wildcard (not sure if I'm using correctly), however, I cant seem to get it to work and would love some guidance. Here's part of the code I am currently working on:

    IF Email_Domain = '%build%' |
    Email_Domain = '%constr%' 
    GroupedEmailDomains=1.

    Email_Domain = '%arch%' 
    GroupedEmailDomains=2.

    EXECUTE.

    Here's an example of a fake email that I'd like to have classified as 1 in the new field using the syntax code: Prattconstructionexperts.com

    Here's an example of a fake email that I'd like to have classified as 2 in the new field using the syntax code: kevinarchitectectsAZ.com

    Thank you for your help!



    ------------------------------
    Frederick Pratt
    ------------------------------



  • 2.  RE: Using wildcards in the IF command together with a string variable

    Posted Fri July 28, 2023 11:40 AM
    That "wildcard" notation does not work in SPSS in that context.  Instead use the CHAR.INDEX function, e.g.
    IF CHAR.INDEX(Email_Domain, "build") > 0 GroupedEmailDomains = 1.
    This is case sensitive, so if you need it to be case insensitive, wrap the variable name in the lower() function.

    If you have a whole block of these tests, consider using the DO IF .. ELSE IF ... version of the test.







  • 3.  RE: Using wildcards in the IF command together with a string variable

    Posted Fri July 28, 2023 12:01 PM

    Beautiful! Thanks for your help!



    ------------------------------
    Fred Pratt
    ------------------------------