Date: Tue, 9 Mar 2010 17:11:12 +0100
Reply-To: Marta García-Granero <mgarciagranero@gmail.com>
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: Marta García-Granero <mgarciagranero@gmail.com>
Subject: Re: One String Variable into Many Binary Variables
In-Reply-To: <201003091547.o29Bkqqh015402@malibu.cc.uga.edu>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Joseph Schneider wrote:
> I have a string variable that I need to decompose into multiple binary
> variables. The String Variable potentially has the following characters:
>
> Name A(comments) Name B (comments) Name C (comments)
>
> I need to create a data set that decomposes this into binary data ie
> create a variable called nameA, so for every case that contains Name A,
> this new variable will have a 1, and a 0, if name A is not present, so the
> new dataset will look like:
>
>
> nameA nameB nameC
> Name A(comments) Name B (comments) Name C (comments) 1 1 1
> Name A(comments) Name B (comments) 1 1 0
> Name A(comments) Name C (comments) 1 0 1
> Name A Name B 1 1 0
>
>
> So there is avaraible created for each potential name.
> Now, here is the fun part, the names are not always in that order, and
> they are not always followed by comments. Any ideas? Hand is out there
> are over 5000 cases.
>
>
Hi Joe:
This should work:
* Sample dataset *.
DATA LIST LIST/StringVar(A55).
BEGIN DATA
"Name A(comments) Name B (comments) Name C (comments)"
"Name A(comments) Name B (comments)"
"Name A(comments) Name C (comments)"
"Name A Name B"
END DATA.
NUMERIC NameA NameB NameC (F8).
COMPUTE NameA=0.
COMPUTE NameB=0.
COMPUTE NameC=0.
IF (INDEX(StringVar,"Name A")>0) NameA = 1 .
IF (INDEX(StringVar,"Name B")>0) NameB = 1 .
IF (INDEX(StringVar,"Name C")>0) NameC = 1 .
LIST.
HTH,
Marta GG
=====================
To manage your subscription to SPSSX-L, send a message to
LISTSERV@LISTSERV.UGA.EDU (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
|