• Replacing part of a string

    From Erin Holloway@21:1/5 to All on Tue Jan 26 19:18:44 2021
    Hoping you could help me write some syntax. I need to replace some text in my string. It needs to be replicated frequently so need to be syntax rather than do a find and replace (ctr+H etc).

    My data FutureCare_1 to FutureCare_30:
    4~4~Continue with current service stream~Continue with current service stream~25~5~5~3
    5~5~5~5
    5
    4~32~Continue with current service stream~~Continue with current service stream~Continue with current service stream
    4~Undetermined – recommended care pathway is still being formulated (only select if further initial assessment and/or engagement is required for intake
    5~4~4~27



    Specifically, anytime the terms:
    "Continue with current service stream"
    "Undetermined – recommended care pathway is still being formulated (only select if further initial assessment and/or engagement is required for intake purposes)".
    come up I would like to replace them with 48 and 39 respectively, across 30 variables (FutureCare_1 to FutureCare_30).

    So basically this, but over 30 variables:

    replace(FutureCare_1 to FutureCare_30,'Continue with current service stream','48').

    replace(FutureCare_1 to FutureCare_30,"Undetermined – recommended care pathway is still being formulated (only select if further initial assessment and/or engagement is required for intake purposes)", "39").

    THanks in advance,
    Erin

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rich Ulrich@21:1/5 to erin.psychology@gmail.com on Wed Jan 27 14:18:35 2021
    On Tue, 26 Jan 2021 19:18:44 -0800 (PST), Erin Holloway <erin.psychology@gmail.com> wrote:


    So basically this, but over 30 variables:

    replace(FutureCare_1 to FutureCare_30,'Continue with current service stream','48').

    replace(FutureCare_1 to FutureCare_30,"Undetermined – recommended care pathway is still being formulated (only select if further initial assessment and/or engagement is required for intake purposes)", "39").

    The first argument for replace( ) should be a variable, not a list.

    DO REPEAT dum1= FutureCare_1 to FutureCare_30.
    replace(dum1,'Continue with current service stream','48').

    replace(dum1,"Undetermined – recommended care pathway is still being formulated (only select if further initial assessment and/or
    engagement is required for intake purposes)", "39").
    END REPEAT.

    Or, you could use a LOOP if you first define the Vector.

    --
    Rich Ulrich

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rich Ulrich@21:1/5 to rich.ulrich@comcast.net on Thu Jan 28 14:48:01 2021
    On Wed, 27 Jan 2021 14:18:35 -0500, Rich Ulrich
    <rich.ulrich@comcast.net> wrote:

    On Tue, 26 Jan 2021 19:18:44 -0800 (PST), Erin Holloway ><erin.psychology@gmail.com> wrote:


    So basically this, but over 30 variables:

    replace(FutureCare_1 to FutureCare_30,'Continue with current service stream','48').

    replace(FutureCare_1 to FutureCare_30,"Undetermined – recommended care pathway is still being formulated (only select if further initial assessment and/or engagement is required for intake purposes)", "39").

    The first argument for replace( ) should be a variable, not a list.

    DO REPEAT dum1= FutureCare_1 to FutureCare_30.
    replace(dum1,'Continue with current service stream','48').

    replace(dum1,"Undetermined – recommended care pathway is still being >formulated (only select if further initial assessment and/or
    engagement is required for intake purposes)", "39").
    END REPEAT.

    Or, you could use a LOOP if you first define the Vector.

    I've never tried to deal with VERY LONG text answers. Text vars
    of any length are not usable in many SPSS procedures, so I
    would usually want a numeric coding.

    If yours were generated by computer, perhaps there are no
    typos. But I would distrust that assumption.

    Consider AUTORECODE.

    AUTORECODE can convert every text answer to a number,
    answers ordered alphabetically. Inspecting the output of FREQ
    (fo instance) can show you where there are two versions of
    the same answer -- a problem to be fixed before going further.

    The /GROUP command will tell SPSS to use the same template
    for all the variables, which is something you will want.

    Depending on circumstances -- I would consider creating a very
    short set of dummy data for the purpose of including each and
    every legitimate answer once, and SAVE that result as a template.
    Using /GROUP, you could get 60 answers coded into two records.

    Then when you APPLY TEMPLATE on your actual data, any answers
    that don't fit will be appended to the end, where they are easy
    to find.


    --
    Rich Ulrich

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