Converting string to numeric

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

Converting string to numeric

leah rubin
Dear Listserv,

I am having difficultly converting a string variable in the following format (1.58E+06) to a number.
Any help would be greatly appreciated.

Thanks in advance,
Leah


Reply | Threaded
Open this post in threaded view
|

RE: Converting string to numeric

MaxJasper
Message
In var definition tab, click change var type from string to numerical.
 
Max

I am having difficultly converting a string variable in the following format (1.58E+06) to a number.
Any help would be greatly appreciated.

Thanks in advance,
Leah

 
Reply | Threaded
Open this post in threaded view
|

Re: Converting string to numeric

Bruce Weaver
Administrator
In reply to this post by leah rubin
leah rubin wrote
Dear Listserv,

I am having difficultly converting a string variable in the following format
(1.58E+06) to a number.
Any help would be greatly appreciated.

Thanks in advance,
Leah
You could use the "convert" option for RECODE.  See the example below.

data list list / stringvar (a12).
begin data
"1.58E+06"
end data.

recode stringvar (convert) into numvar.
formats numvar f15.2 .
list.

--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).
Reply | Threaded
Open this post in threaded view
|

Re: Converting string to numeric

ViAnn Beadle
In reply to this post by leah rubin

This is a number and not a string. What you are seeing is exponential format. Where do you see this—in the data editor or the viewer?

 

From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of leah rubin
Sent: Monday, February 07, 2011 10:24 AM
To: [hidden email]
Subject: Converting string to numeric

 

Dear Listserv,

I am having difficultly converting a string variable in the following format (1.58E+06) to a number.
Any help would be greatly appreciated.

Thanks in advance,
Leah

Reply | Threaded
Open this post in threaded view
|

Re: Converting string to numeric

John Cica
In reply to this post by Bruce Weaver
Could it be as simple as physically widening the column in the data set so
that the number appears instead of the scientific counterpart?

> leah rubin wrote:
>>
>> Dear Listserv,
>>
>> I am having difficultly converting a string variable in the following
>> format
>> (1.58E+06) to a number.
>> Any help would be greatly appreciated.
>>
>> Thanks in advance,
>> Leah
>>
>>
>
> You could use the "convert" option for RECODE.  See the example below.
>
> data list list / stringvar (a12).
> begin data
> "1.58E+06"
> end data.
>
> recode stringvar (convert) into numvar.
> formats numvar f15.2 .
> list.
>
>
>
> -----
> --
> Bruce Weaver
> [hidden email]
> http://sites.google.com/a/lakeheadu.ca/bweaver/
>
> "When all else fails, RTFM."
>
> NOTE: My Hotmail account is not monitored regularly.
> To send me an e-mail, please use the address shown above.
>
> --
> View this message in context:
> http://spssx-discussion.1045642.n5.nabble.com/Converting-string-to-numeric-tp3374613p3374714.html
> Sent from the SPSSX Discussion mailing list archive at Nabble.com.
>
> =====================
> 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
Reply | Threaded
Open this post in threaded view
|

Re: Converting string to numeric

Bruce Weaver
Administrator
That will do it IF it is actually a numeric variable.  But Leah said in the original post that it is stored as a string variable.  If that is true, widening the column will not change anything.

The column width in the data editor can be changed via the VARIABLE WIDTH command, by the way.  E.g., adding to the example I posted earlier:

variable width numvar (7).
* Stop now and look at the data editor.
* You should see NUMVAR = 1.58+006 .

variable width numvar (8).
* Look at the data editor again.
* You should see NUMVAR = 1580000.00 .


HTH.


John Cica wrote
Could it be as simple as physically widening the column in the data set so
that the number appears instead of the scientific counterpart?

> leah rubin wrote:
>>
>> Dear Listserv,
>>
>> I am having difficultly converting a string variable in the following
>> format
>> (1.58E+06) to a number.
>> Any help would be greatly appreciated.
>>
>> Thanks in advance,
>> Leah
>>
>>
>
> You could use the "convert" option for RECODE.  See the example below.
>
> data list list / stringvar (a12).
> begin data
> "1.58E+06"
> end data.
>
> recode stringvar (convert) into numvar.
> formats numvar f15.2 .
> list.
>
>
>
> -----
> --
> Bruce Weaver
> bweaver@lakeheadu.ca
> http://sites.google.com/a/lakeheadu.ca/bweaver/
>
> "When all else fails, RTFM."
>
> NOTE: My Hotmail account is not monitored regularly.
> To send me an e-mail, please use the address shown above.
>
> --
> View this message in context:
> http://spssx-discussion.1045642.n5.nabble.com/Converting-string-to-numeric-tp3374613p3374714.html
> Sent from the SPSSX Discussion mailing list archive at Nabble.com.
>
> =====================
> To manage your subscription to SPSSX-L, send a message to
> LISTSERV@LISTSERV.UGA.EDU (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
LISTSERV@LISTSERV.UGA.EDU (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
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).
Reply | Threaded
Open this post in threaded view
|

Re: Converting string to numeric

lucameyer
In reply to this post by Bruce Weaver
Just a small correction to Bruce's suggested sample syntax: parentheses should be put around the format command, that is:

///
data list list / stringvar (a12).
begin data
"1.58E+06"
end data.

recode stringvar (convert) into numvar.
formats numvar (f15.2).
list.
///

Cheers,
Luca


Mr. Luca Meyer
www.lucameyer.com