Discussion:
Replacing part of a string
(too old to reply)
Erin Holloway
2021-01-27 03:18:44 UTC
Permalink
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
Rich Ulrich
2021-01-27 19:18:35 UTC
Permalink
On Tue, 26 Jan 2021 19:18:44 -0800 (PST), Erin Holloway
Post by Erin Holloway
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
Rich Ulrich
2021-01-28 19:48:01 UTC
Permalink
On Wed, 27 Jan 2021 14:18:35 -0500, Rich Ulrich
Post by Rich Ulrich
On Tue, 26 Jan 2021 19:18:44 -0800 (PST), Erin Holloway
Post by Erin Holloway
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
Loading...