Converting String to Number

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

Converting String to Number

Eugenio Grant
Hi:



I have this syntax



COMPUTE V002 = NUMBER(V001,F8.0).



It creates a new variable BUT with 2 numbers to the right of the decimal
like this 2,00  3,00 etc. No matter what I try to do it always creates the
same 2 decimal points, is there a way to create the Variable without going
then to the FORMATS so the variable is computed with no decimal points.
Reply | Threaded
Open this post in threaded view
|

Re: Converting String to Number

Raynald Levesque
Hi Eugenio,

The format of any new variable (not previously declared) is determined by
the default format then in effect. To change the default format to have F8.0
instead of F8.2, use the command
SET FORMAT=F8.0.

If you do that, then the variable V002 created by your command
COMPUTE V002 = NUMBER(V001,F8.0).
will have the format F8.0. Any other new numeric variables will also have
format F8.0 unless you run a new SET FORMAT command.

Regards,

Raynald Levesque [hidden email]
Website: www.spsstools.net

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Eugenio Grant
Sent: January 29, 2007 8:22 PM
To: [hidden email]
Subject: Converting String to Number

Hi:



I have this syntax



COMPUTE V002 = NUMBER(V001,F8.0).



It creates a new variable BUT with 2 numbers to the right of the decimal
like this 2,00  3,00 etc. No matter what I try to do it always creates the
same 2 decimal points, is there a way to create the Variable without going
then to the FORMATS so the variable is computed with no decimal points.
Reply | Threaded
Open this post in threaded view
|

Re: Converting String to Number

Judith Saebel
The other option (via pull-down menu) is to go

     Edit -> Options -> Data-> Display Format for New Numeric Variables
->

     Decimal Places and then type in/choose 0.

But as Raynald says, from then on, all new variables will have this new
format, until you run a new syntax or make the changes through the
Edit->Options menu.


Regards,

Judith Saebel



-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Raynald Levesque
Sent: Tuesday, 30 January 2007 12:16
To: [hidden email]
Subject: Re: Converting String to Number

Hi Eugenio,

The format of any new variable (not previously declared) is determined
by
the default format then in effect. To change the default format to have
F8.0
instead of F8.2, use the command
SET FORMAT=F8.0.

If you do that, then the variable V002 created by your command
COMPUTE V002 = NUMBER(V001,F8.0).
will have the format F8.0. Any other new numeric variables will also
have
format F8.0 unless you run a new SET FORMAT command.

Regards,

Raynald Levesque [hidden email]
Website: www.spsstools.net

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Eugenio Grant
Sent: January 29, 2007 8:22 PM
To: [hidden email]
Subject: Converting String to Number

Hi:



I have this syntax



COMPUTE V002 = NUMBER(V001,F8.0).



It creates a new variable BUT with 2 numbers to the right of the decimal
like this 2,00  3,00 etc. No matter what I try to do it always creates
the
same 2 decimal points, is there a way to create the Variable without
going
then to the FORMATS so the variable is computed with no decimal points.
Reply | Threaded
Open this post in threaded view
|

Re: Converting String to Number

Richard Ristow
In reply to this post by Eugenio Grant
At 08:21 PM 1/29/2007, Eugenio Grant wrote:

>COMPUTE V002 = NUMBER(V001,F8.0).
>
>It creates a new variable BUT with 2 numbers to the right of the
>decimal like this 2,00  3,00 etc. No matter what I try to do it always
>creates the same 2 decimal points, is there a way to create the
>Variable without going then to the FORMATS so the variable is computed
>with no decimal points.

You've had the answer: there's no way to get what you want but to
change the display format, from the menu or with the FORMATS command.

Raynald Levesque and Judith Saebel suggested ways that change the
formats for all new numeric variables. I'd suggest that, since you're
already using syntax, it's simplest to use a FORMATS command:

COMPUTE V002 = NUMBER(V001,F8.0).
FORMATS V002 (F8.0).

Now, an important clarification: you asked if "the variable [can be]
computed with no decimal points". The answer is, it can't. SPSS numbers
don't have a set number, or any number, of decimal places. They do let
a number have a fractional part, but it's not of a specific number of
decimals.

You want your number to *display* with no decimal places. That's fine,
but you should not think that that means it *has* no decimal places.
You shouldn't thank that it has any decimal places, either. The concept
concerns the number's display form (which FORMATS specifies),  but not
the number itself.