Irritating format

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

Irritating format

Robert L

When I convert a string variable into a numeric one, there should be a component specifying the numeric format. However, it doesn't end up the way I think it should. Instead of the format specified, it ends up as the default F8.2 format and I have to alter the type afterwards. Is there anything I have to set up differently in the options? It's really not a big problem, but it is annoying enough.

 

Code that should (?) result in a F10.0 variable, a sequence beginning with a numeric variable pnum out of which the two first digits are left out and then converted back to a numeric format:

 

COMPUTE pnr=number(char.substr(string(pnum,F12.0),3),F10.0).

 

Any hints?

 

Robert

Robert Lundqvist
Reply | Threaded
Open this post in threaded view
|

Re: Irritating format

Albert-Jan Roskam
________________________________

>From: Robert Lundqvist <[hidden email]>
>To: [hidden email]
>Sent: Tuesday, September 11, 2012 10:02 AM
>Subject: [SPSSX-L] Irritating format
>
>
>When I convert a string variable into a numeric one, there should be a component specifying the numeric format. However, it doesn't end up the way I think it should. Instead of the format specified, it ends up as the default F8.2 format and I have to alter the type afterwards. Is there anything I have to set up differently in the options? It's really not a big problem, but it is annoying enough.
>
>Code that should (?) result in a F10.0 variable, a sequence beginning with a numeric variable pnum out of which the two first digits are left out and then converted back to a numeric format:
>
>COMPUTE pnr=number(char.substr(string(pnum,F12.0),3),F10.0).
>
>Any hints?
>
Hi,

You could use
set format = f10.
But in practice this is also not always what one wants.

Albert-Jan

=====================
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: Irritating format

Jon K Peck
In reply to this post by Robert L
New numeric variables are given the default numeric format (F8.2 if you haven't changed preferences).  This can be changed with the FORMAT command, of course,

But you can also use the ALTER TYPE command to do the conversion, and it accepts an output format.  For example,
alter type str (F6.0).
would convert the variable str to a numeric variable with an F6.0 format.

HTH,

Jon Peck (no "h") aka Kim
Senior Software Engineer, IBM
[hidden email]
new phone: 720-342-5621




From:        Robert Lundqvist <[hidden email]>
To:        [hidden email]
Date:        09/11/2012 02:41 AM
Subject:        [SPSSX-L] Irritating format
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




When I convert a string variable into a numeric one, there should be a component specifying the numeric format. However, it doesn't end up the way I think it should. Instead of the format specified, it ends up as the default F8.2 format and I have to alter the type afterwards. Is there anything I have to set up differently in the options? It's really not a big problem, but it is annoying enough.
 
Code that should (?) result in a F10.0 variable, a sequence beginning with a numeric variable pnum out of which the two first digits are left out and then converted back to a numeric format:
 
COMPUTE pnr=number(char.substr(string(pnum,F12.0),3),F10.0).
 
Any hints?
 
Robert