SPSS Statistics

SPSS Statistics

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

 View Only
  • 1.  Recode into Diff Variables

    Posted Fri February 25, 2022 10:28 AM
    Hey everyone,

    I'm working with a large dataset that has multiple variables I'd like to combine/split into 3 diff cohorts/ new variable to compare. The variables I'd like to separate are Var1, Var2, Var3, Var4, etc. End goal: Create a new variable with the cases identified as either CohortA, CohortB, or CohortC. 

    Cohort A : (Var1= bus1 or Var1 = bus2), but doesn't include (Var2=toy1 or Var3=toy1 or Var4...)

    Cohort B: (Var1 = bus1 or Var1=bus2) and includes (Var2=toy1 or Var3=toy1 or Var4...)

    Cohort C: Var1 = toy1 or Var1 = toy2

    Here is the syntax I'm using: 

    Select if ((VAR1 = '49560' OR VAR1 = '49561' OR VAR1 = '49565' OR VAR1 = '49566' OR VAR1 = '49568') AND VAR2 <> '15830' OR VAR2 <> '15847' OR VAR3 <> '15830' OR VAR3 <> '15847' OR VAR4 <> '15830' OR VAR4 <> '15847' OR VAR5 <> '15830' OR VAR5 <> '15847' OR VAR6 <> '15830' OR VAR6 <> '15847' OR VAR7 <> '15830' OR VAR7 <> '15847' OR VAR8 <> '15830' OR VAR8 <> '15847' OR VAR9 <> '15830' OR VAR9 <> '15847' OR VAR10 <> '15830' OR VAR10 <> '15847' OR VAR11 <> '15830' OR VAR11 <> '15847').


    Getting error code: Incorrect variable name: either the name is more than 64 characters, or it is not defined by a previous command

    I know my variable name is correct. I have quadrupled checked. And they are not longer than 64 characters. I am guessing it is a problem with an operator I'm using. Please help :)

    ------------------------------
    Cindy Gombaut
    ------------------------------

    #SPSSStatistics


  • 2.  RE: Recode into Diff Variables

    Posted Fri February 25, 2022 10:36 AM
    These are all string variables? OK, if so...
    I would try to simplify some of this with the ANY function, which will also work with NOT before it. I show that below.

    For example:

    SELECT IF ANY(Var1, '49560','49561','49565', '49566','49568') AND NOT(ANY(VAR2,'15830','15847')) OR NOT(ANY(VAR3,'15830','15847')) OR NOT(ANY(VAR4,'15830','15847')) etc for the rest.

    If you are still getting problems, break it into steps.

    SELECT IF ANY(Var1,'49560','49561','49565', '49566','49568').
    EXECUTE.
    ** Make sure that gave no errors.
    SELECT IF NOT(ANY(Var2, 'value1','value2','etc')).
    ** etc.

    ------------------------------
    Rick Marcantonio
    Quality Assurance
    IBM
    ------------------------------



  • 3.  RE: Recode into Diff Variables

    Posted Mon February 28, 2022 09:42 AM
    Good explenation

    ------------------------------
    Luigi De Fonsi
    ------------------------------



  • 4.  RE: Recode into Diff Variables

    Posted Mon February 28, 2022 04:23 AM
    Hello 

    you wrote "End goal: Create a new variable with the cases identified as either CohortA, CohortB, or CohortC. " 

    with select if you won't create a new variable, you create only a subdata of your previous data

    you can create e.g. a new variable cohortC with : 

    if (Var1 = "toy1" or Var1 = "toy2") CohortC = 1. 

    Regards,




    ------------------------------
    xq OW
    ------------------------------