• SPSS: Script to replace one value by a new value across all variables

    From Adam Smith@21:1/5 to All on Tue Jan 21 05:29:51 2020
    I am quite new to SPSS and I would like to replace the value 999 by 99999 across all my variables. The SPSS dialog "Find & Replace" works for one column/variable at a time only. Can someone help out with a script to make replacement across all variables
    possible?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Bruce Weaver@21:1/5 to Adam Smith on Tue Jan 21 07:20:19 2020
    On Tuesday, January 21, 2020 at 8:29:54 AM UTC-5, Adam Smith wrote:
    I am quite new to SPSS and I would like to replace the value 999 by 99999 across all my variables. The SPSS dialog "Find & Replace" works for one column/variable at a time only. Can someone help out with a script to make replacement across all
    variables possible?

    RECODE ought to do the trick. How efficient you can make the code depends on whether there are any string variables, whether all numeric variables are contiguous in the file, etc. Here's a simple example to get you started.

    DATA LIST LIST / x1 x2 x3 (3F8.0).
    BEGIN DATA
    1 2 4
    999 999 999
    END DATA.

    * If all variables are numeric, use keyword ALL.
    RECODE ALL (999 = 999999).
    EXECUTE.

    * If there is at least one string variable, but numeric variables are contiguous, use keyword TO.
    RECODE x1 to x3 (999 = 999999).
    EXECUTE.

    * If numeric variables are not contiguous, list them, but bear in mind you can use TO
    * in stretches where they are contiguous.

    RECODE x1 TO x2 x3 (999 = 999999).
    EXECUTE.

    * If all numeric variables are surrounded by string variables, list each variable.
    RECODE x1 x2 x3 (999 = 999999).
    EXECUTE.

    HTH.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Adam Smith@21:1/5 to All on Tue Jan 21 08:44:35 2020
    Am Dienstag, 21. Januar 2020 16:20:23 UTC+1 schrieb Bruce Weaver:
    On Tuesday, January 21, 2020 at 8:29:54 AM UTC-5, Adam Smith wrote:
    I am quite new to SPSS and I would like to replace the value 999 by 99999 across all my variables. The SPSS dialog "Find & Replace" works for one column/variable at a time only. Can someone help out with a script to make replacement across all
    variables possible?

    RECODE ought to do the trick. How efficient you can make the code depends on whether there are any string variables, whether all numeric variables are contiguous in the file, etc. Here's a simple example to get you started.

    DATA LIST LIST / x1 x2 x3 (3F8.0).
    BEGIN DATA
    1 2 4
    999 999 999
    END DATA.

    * If all variables are numeric, use keyword ALL.
    RECODE ALL (999 = 999999).
    EXECUTE.

    * If there is at least one string variable, but numeric variables are contiguous, use keyword TO.
    RECODE x1 to x3 (999 = 999999).
    EXECUTE.

    * If numeric variables are not contiguous, list them, but bear in mind you can use TO
    * in stretches where they are contiguous.

    RECODE x1 TO x2 x3 (999 = 999999).
    EXECUTE.

    * If all numeric variables are surrounded by string variables, list each variable.
    RECODE x1 x2 x3 (999 = 999999).
    EXECUTE.

    HTH.

    Great. Thank you a lot!

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)