Date: Tue, 9 Mar 2010 11:18:08 -0500
Reply-To: Mike Palij <mp26@nyu.edu>
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: Mike Palij <mp26@nyu.edu>
Subject: Re: One String Variable into Many Binary Variables
Content-Type: text/plain; charset="iso-8859-1"
You need to be more specific about certain things. For example
are whether all of the Name variables left-justified, that is, every
name starts in the first place/space. If so, consider the following:
STRING test_A, test_B, test_C (a1)
compute test_A=nameA.
compute test_B=nameB.
compute test_C=nameC.
*Note: The test variables are one character long while the name
*variables are some arbitrary length. Setting test = name means
*that only the first position of name is inserted into test -- the
*rest of the name variable is right trimmed; someone correct
*me if this has changed.
compute Dichot_1=0.
compute Dichot_2=0.
compute Dichot_3=0.
if(test_A ne " ")Dichot_1=1.
if(test_B ne " ")Dichot_2=1.
if(test_C ne " ")Dichot_3=1.
Desc var=Dichot_1, Dichot_2, Dichot_3.
The means from the Descriptives procedure will tell you how many
names you have (or how many name fields without initial blanks).
There may be simpler or more elegant ways of doing this. Also
this is based on knowledge of how some old SPSS operations should
procedure.
-Mike Palij
New York University
mp26@nyu.edu
----- Original Message -----
From: "Joseph Schneider" <jschneider5@EARTHLINK.NET>
To: <SPSSX-L@LISTSERV.UGA.EDU>
Sent: Tuesday, March 09, 2010 10:47 AM
Subject: One String Variable into Many Binary Variables
> Dear List,
>
> 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.
>
> Joe
>
> =====================
> 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
=====================
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