adding large number & display in data editor

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

adding large number & display in data editor

wsu_wright
I have 2 id fields I need to combine.

v1                                  v2
920269149300936   81001

compute x=(v1*100000)+v2.
for x (F20.0).

When I do the syntax above, the data editor does not correctly display the new value, often the last 5 values are either all zeros or just 80000.  Any ideas?

David.
Reply | Threaded
Open this post in threaded view
|

Re: adding large number & display in data editor

Richard Ristow
At 08:05 AM 9/6/2007, David Wright wrote:

>I have 2 id fields I need to combine.
>
>v1                v2
>920269149300936   81001
>
>compute x=(v1*100000)+v2.
>for x (F20.0).
>
>When I do the syntax above, the data editor does not correctly display
>the new value, often the last 5 values are either all zeros or just
>80000.

It's not a problem with the data editor. Your combined ID has 20
significant digits. The precision of SPSS numbers is approximately 16
digits, and you're losing low-order digits.(*)

One solution is to make your ID a character string. Something like this
(not tested):

STRING  X_char (A20).
COMPUTE X_char
    = CONCAT(STRING(v1,F15),
             STRING(v2,F05)).
....................
(*) SPSS, and most current applications, represent numbers in the
64-bit floating-p0oint format defined by standard IEEE 754. Precision
is 53 bits, which is very close to 16 decimal digits.
Reply | Threaded
Open this post in threaded view
|

Re: adding large number & display in data editor

Art Kendall-2
In reply to this post by wsu_wright
floating point numbers do not hold that many significant digits.
try this untested syntax.
string v3(a20).
compute v3 = concat(string(v1,f15), string(v1,f5)).
autorecode variables=v3 /into x.

Art Kendall
Social Research Consultants


David Wright wrote:

> I have 2 id fields I need to combine.
>
> v1                                  v2
> 920269149300936   81001
>
> compute x=(v1*100000)+v2.
> for x (F20.0).
>
> When I do the syntax above, the data editor does not correctly display the new value, often the last 5 values are either all zeros or just 80000.  Any ideas?
>
> David.
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: adding large number & display in data editor

Fry, Jonathan B.
In reply to this post by wsu_wright
SPSS stores numbers in 64-bit floating-point representation.  After allowing one bit for the sign and 11 for the exponent, and assuming a leading 1, that leaves enough room for 53 binary digits for the number itself.  That's about 16 decimal digits - not enough for your combined ID.

The only way to represent it in a single variable is as a string.  The following (untested) code should do it:

String x(20).
Compute x = concat(string(v1,n15),string(v2,n5)).

Jonathan Fry
SPSS Inc.

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of David Wright
Sent: Thursday, September 06, 2007 7:05 AM
To: [hidden email]
Subject: adding large number & display in data editor

I have 2 id fields I need to combine.

v1                                  v2
920269149300936   81001

compute x=(v1*100000)+v2.
for x (F20.0).

When I do the syntax above, the data editor does not correctly display the new value, often the last 5 values are either all zeros or just 80000.  Any ideas?

David.