Separating Variables

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Separating Variables

subscribe SPSSX-l Anonymous-2
Hello Group,

I have a field with 3 different numeric variables which I want to separate
out into 3 different fields.  I'm using the CHAR.SUBSTR to try and partition
the variables out.  But it's not working because that's a STRING function
not a NUMERIC function.  I don't want to loose any of the zero's at the
beginning of the variable, is there no way around that if I'm trying to
separate it out to 3 different fields?  Would the Restructure command in
SPSS work out better in my case.

Sample Data:

0429708 0345989 0098747

I need these variables separated out in 3 different fields.

Thanks in advance,

MK

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (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
Reply | Threaded
Open this post in threaded view
|

Re: Separating Variables

Art Kendall
Pleas tell us more about what you are trying to do?
Where is this field?
Is this data that is already in a package?  A numeric field would not
have embedded blanks in most display formats.
Is it character data in fixed columns? .txt? .asc? etc?
Is it already in SPSS?  If it is, are you sure it is numeric?


Art Kendall
Social Research Consultants

subscribe SPSSX-l Anonymous wrote:

> Hello Group,
>
> I have a field with 3 different numeric variables which I want to separate
> out into 3 different fields.  I'm using the CHAR.SUBSTR to try and partition
> the variables out.  But it's not working because that's a STRING function
> not a NUMERIC function.  I don't want to loose any of the zero's at the
> beginning of the variable, is there no way around that if I'm trying to
> separate it out to 3 different fields?  Would the Restructure command in
> SPSS work out better in my case.
>
> Sample Data:
>
> 0429708 0345989 0098747
>
> I need these variables separated out in 3 different fields.
>
> Thanks in advance,
>
> MK
>
> =====================
> To manage your subscription to SPSSX-L, send a message to
> [hidden email] (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
[hidden email] (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
Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: Separating Variables

Art Kendall
Something like this untested syntax should do it.
*as a string.
string instructor1 to instructor3 (a7).
compute instructor1 = substr(mystring, 1,7).
compute instructor2 = substr(mystring, 9,7).
compute instructor3 = substr(mystring,17,7).

* or as a number with leading zeros.
numeric n_instructor1 to n_instructor2 (n7).
compute n_instructor1 = number(substr(mystring, 1,7),n7).
compute n_instructor2 = number(substr(mystring, 9,7),n7).
compute n_instructor3 = number(substr(mystring,17,7),n7).

Art Kendall
Social Research Consultants


Michelle Kors wrote:
Hello Art,

The original file I had came from Excel (which was pulled from Datatel) and imported into SPSS.  This data is already packaged with 3 different variables in one field as such 0478987 0568984 0898982 (7 characters each with the spaces included between each set of numbers).  You are indeed correct, this field is not numeric.  These are cross-listed course numberings and they all have the same classroom and that is why this particular case along with many others have 3 different instructor IDs in one field.

I just want to know if there's a simpler way to take these 3 different instructor ID's (which are all in one case) and separate them out to 3 different fields.

Thanks,

MK






---------- Forwarded message ----------
From: Art Kendall [hidden email]
To: [hidden email]
Date: Thu, 19 Feb 2009 15:30:53 -0500
Subject: Re: Separating Variables
Pleas tell us more about what you are trying to do?
Where is this field?
Is this data that is already in a package?  A numeric field would not
have embedded blanks in most display formats.
Is it character data in fixed columns? .txt? .asc? etc?
Is it already in SPSS?  If it is, are you sure it is numeric?


Art Kendall
Social Research Consultants

subscribe SPSSX-l Anonymous wrote:
Hello Group,

I have a field with 3 different numeric variables which I want to separate
out into 3 different fields.  I'm using the CHAR.SUBSTR to try and partition
the variables out.  But it's not working because that's a STRING function
not a NUMERIC function.  I don't want to loose any of the zero's at the
beginning of the variable, is there no way around that if I'm trying to
separate it out to 3 different fields?  Would the Restructure command in
SPSS work out better in my case.

Sample Data:

0429708 0345989 0098747

I need these variables separated out in 3 different fields.

Thanks in advance,

MK

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (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
[hidden email] (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


Art Kendall
Social Research Consultants