how mto divide an variable

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

how mto divide an variable

Leo Bakker
Dear listers,

I have a variable with two positions (15, 25 or 35 etc.)
These two positions have different meanings, but they are connected when
downloaded from an sql server.

Is it possible to divide this variable in two separate variables when
they're already in spss?
like 15 becomes two new vars 1 and 5, 25 becomes 2 and 5 etc.

Your help is very much appreciated! Thank you in advance!
Leo
Reply | Threaded
Open this post in threaded view
|

Re: how mto divide an variable

xiaoqin.wan@gmail.com
Hi,

If your variable is numeric, you can try:

compute var1 = trunc(var/10).
compute var2 = mod(var, 10).

If your variable is string, you can try:

string var1 var2(a1).

compute var1 = substr(var, 1, 1).
compute var2 = substr(var, 2, 1).

HTH,

baiyun




2007/10/11, Leo Bakker <[hidden email]>:

>
> Dear listers,
>
> I have a variable with two positions (15, 25 or 35 etc.)
> These two positions have different meanings, but they are connected when
> downloaded from an sql server.
>
> Is it possible to divide this variable in two separate variables when
> they're already in spss?
> like 15 becomes two new vars 1 and 5, 25 becomes 2 and 5 etc.
>
> Your help is very much appreciated! Thank you in advance!
> Leo
>
Reply | Threaded
Open this post in threaded view
|

Re: how mto divide an variable

Marta Garcia-Granero
In reply to this post by Leo Bakker
Hi Leo:

It should be quite simple.

DATA LIST LIST/var(F8).
BEGIN DATA
15
25
35
END DATA.
NUMERIC pos1 pos2 (F8).
COMPUTE pos1 = TRUNC(var/10) .
COMPUTE pos2 = var - 10*pos1.
LIST.

HTH,
Marta Garcia-Granero

> I have a variable with two positions (15, 25 or 35 etc.)
> These two positions have different meanings, but they are connected when
> downloaded from an sql server.
>
> Is it possible to divide this variable in two separate variables when
> they're already in spss?
> like 15 becomes two new vars 1 and 5, 25 becomes 2 and 5 etc.
>