Date: Wed, 1 Apr 1998 18:09:36 -0600
Reply-To: "Tverdek, Edward" <etverdek@SPSS.COM>
Sender: "SPSSX(r) Discussion" <SPSSX-L@UGA.CC.UGA.EDU>
From: "Tverdek, Edward" <etverdek@SPSS.COM>
Subject: Re: Variable separation
SPSS's own invaluable David Matheson is the first to come up
with one of the "easier ways" I mentioned. Since the values you
have are already 0s and 1s, you can extract the actual digits
rather than, as I suggested, computing a logical variable based
on the value of the division remainder (MODulo). In addition,
7-#i is, of course, equivalent to the absolute value of #i-7.
The following simplification from David will get you the same
results with less room for headaches.
LOOP #i=1 TO 7.
COMPUTE x(#i)= MOD(TRUNC(v1/10**(7-#i)),10).
formats x1 to x7 (f3).
Again, I hope this helps.
SPSS Technical Support
>From: Tverdek, Edward
>Sent: Wednesday, April 01, 1998 1:42 PM
>To: SPSSX-L@UGA.CC.UGA.EDU; 'M. MILLS'
>Subject: RE: Variable separation
>How you might extract these values into an array of
>dichotomous variables will depend on how you've read
>the "v1" variable from the .dbf file. If you have
>read it as a string, you can extract the individual
>variables with a series COMPUTE statements involving
>the SUBSTR (substring) command. If you were hoping to
>treat the resulting dichotomies as numeric, it would be
>necessary to convert them to this format, either on the
>fly with the NUMBER function or with a RECODE...(CONVERT)
>...INTO once each new dichotomy has been extracted.
>This being said, you might have an easier time of it if you
>can read the "v1" variable as numeric and extract your
>individual dichotomous variables conditionally. Here's a
>small sample job which seems to work for the cases you provide,
>and which I think might be useable in general (you would need
>to adjust some arguments in obvious places depending on how
>long the string of digits is and how many variables you wanted
>to pull out of it). There may be an easier way to do this,
>but this example ought to get you started.
>I hope this helps,
>SPSS Technical Support
>*This just reads a few cases along the lines you describe.
>data list /v1 1-7.
>*Here's the relevant part.
>LOOP #i=1 TO 7.
>COMPUTE x(#i)=(MOD(TRUNC(newv1/10**(ABS(#i-7))),10) NE 0).
>From: M. MILLS[SMTP:m.mills@FRW.RUG.NL]
>Sent: Wednesday, April 01, 1998 4:02 AM
>Subject: Variable separation
>I would like some advice regarding the 'splitting' or 'separating' of
>one variable into several parts. I received a series of '*.dbf' files,
>which I transferred to SPSS. However, I found that
>certain series of questions were collapsed into one variable. For
>example, the 'type of education' variable, is currently:
>Whereas, I need it arranged into seven separate dichotomous variables
>with values of 0 & 1.
>v1 v2 v3 v4 v5 v6 v7
>0 0 1 1 0 0 1
>Does anyone have any suggestions about how to separate these
>variables? Thank you very much for taking the time to help.
>Population Research Centre, Faculty of Spatial Sciences
>P.O. Box 800
>9700 AV Groningen
>Tel: +31 50 363 3898 Fax: +31 50 363 3901