SPSS Statistics

SPSS Statistics

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

 View Only

Using syntax to recode string data differently based upon age

  • 1.  Using syntax to recode string data differently based upon age

    Posted Fri March 11, 2022 09:57 AM
    I'm trying to recode a bunch of data in IBM SPSS Statistics 24.  With these data, there weren't a lot of data quality parameters put in place on the front end, so I'm cleaning and recoding data on the backend.  I have to recode the data differently based upon age.  The system didn't have a NA due to age response option.  I want to make sure that anyone who is less than 5 years old, if they responded, I want their response to become NA due to age.  


    STRING R_WALKCLIMB_RECODED_USE_ME (A100).
    DO IF (ee_AGE_RECODED>=5).
    RECODE r_DisabilityWalkClimb ('D'='Declined') ('Declined'='Declined') ("Don't know"='Unknown')
    ("Don't want to answer"='Declined') ('N'='No') ('No'='No') ('U'='Unknown') ('Unknown'='Unknown')
    ('Y'='Yes') ('Yes'='Yes') INTO R_WALKCLIMB_RECODED_USE_ME.
    ELSE IF (ee_AGE_RECODED<=5).
    RECODE r_DisabilityWalkClimb ('D'='NA due to age') ('Declined'='NA due to risk') ("Don't know"='NA due to age')
    ("Don't want to answer"='NA due to age') ('N'='NA due to age') ('No'='NA due to age') ('U'='NA due to age') ('Unknown'='NA due to age')
    ('Y'='NA due to age') ('Yes'='NA due to age') INTO R_WALKCLIMB_RECODED_USE_ME.
    VARIABLE LABELS R_WALKCLIMB_RECODED_USE_ME 'R_WALKCLIMB_RECODED_USE_ME'.
    EXECUTE.

    Here's the error messages I have gotten:
    >Warning # 142. Command name: EXECUTE
    >LOOP has no effect on this command.

    >Error # 4095. Command name: EXECUTE
    >The transformations program contains an unclosed LOOP, DO IF, or complex file
    >structure. Use the level-of-control shown to the left of the SPSS Statistics
    >commands to determine the range of LOOPs and DO IFs.
    >Execution of this command stops.
    FREQUENCIES VARIABLES=R_WALKCLIMB_RECODED_USE_ME

    >Warning # 142. Command name: FREQUENCIES
    >LOOP has no effect on this command.

    >Error # 4095. Command name: FREQUENCIES
    >The transformations program contains an unclosed LOOP, DO IF, or complex file
    >structure. Use the level-of-control shown to the left of the SPSS Statistics
    >commands to determine the range of LOOPs and DO IFs.
    >Execution of this command stops.
    /ORDER=ANALYSIS.

    Any help you could provide would be greatly appreciated!  Thanks!

    ------------------------------
    Jacob Melson
    ------------------------------

    #SPSSStatistics