Changing variable type

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

Changing variable type

Chris Hunt

Hi all,

Can anybody tell me how to change a variable from string to numeric using code.  I have looked through help but to no avail.  The variable in question contains numerical data only but imports as text.

Many thanks

Chris

Reply | Threaded
Open this post in threaded view
|

Re: Changing variable type

Jignesh Sutar
There are are a number of ways to do this. ALTER TYPE would work if running the latest version of SPSS.
 
Otherwise, you have RECODE option using the keyword CONVERT.
 
And also a COMPUTE command with NUMBER function such as
 
Compute NumbVar=NUMBER(strVar,F8.0).
 
HTH,
Jignesh
On 15 December 2010 12:15, Chris Hunt <[hidden email]> wrote:

Hi all,

Can anybody tell me how to change a variable from string to numeric using code.  I have looked through help but to no avail.  The variable in question contains numerical data only but imports as text.

Many thanks

Chris


Reply | Threaded
Open this post in threaded view
|

Re: Changing variable type

Chris Hunt

Perfect, thank you.

ALTER TYPE does exactly what I want.

I had tried RECODE and CONVERT but then I was having to delete the old variable and rename the new one which seemed long winded to me.

 

 

 

From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of J Sutar
Sent: 15 December 2010 12:45
To: [hidden email]
Subject: Re: Changing variable type

 

There are are a number of ways to do this. ALTER TYPE would work if running the latest version of SPSS.

 

Otherwise, you have RECODE option using the keyword CONVERT.

 

And also a COMPUTE command with NUMBER function such as

 

Compute NumbVar=NUMBER(strVar,F8.0).

 

HTH,

Jignesh

On 15 December 2010 12:15, Chris Hunt <[hidden email]> wrote:

Hi all,

Can anybody tell me how to change a variable from string to numeric using code.  I have looked through help but to no avail.  The variable in question contains numerical data only but imports as text.

Many thanks

Chris

 

Reply | Threaded
Open this post in threaded view
|

Re: Changing variable type

Rick Oliver-3
In reply to this post by Jignesh Sutar
Alter Type was introduced in version 16.



From:        J Sutar <[hidden email]>
To:        [hidden email]
Date:        12/15/2010 06:56 AM
Subject:        Re: Changing variable type
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




There are are a number of ways to do this. ALTER TYPE would work if running the latest version of SPSS.
 
Otherwise, you have RECODE option using the keyword CONVERT.
 
And also a COMPUTE command with NUMBER function such as
 
Compute NumbVar=NUMBER(strVar,F8.0).
 
HTH,
Jignesh
On 15 December 2010 12:15, Chris Hunt <crh75@...> wrote:
Hi all,

Can anybody tell me how to change a variable from string to numeric using code.  I have looked through help but to no avail.  The variable in question contains numerical data only but imports as text.

Many thanks

Chris

Reply | Threaded
Open this post in threaded view
|

Re: Changing variable type

Rick Oliver-3
In reply to this post by Chris Hunt
And ALTER TYPE leaves the variable in the same location in the file, if that makes any difference for what you want to do.



From:        Chris Hunt <[hidden email]>
To:        [hidden email]
Date:        12/15/2010 07:36 AM
Subject:        Re: Changing variable type
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




Perfect, thank you.
ALTER TYPE does exactly what I want.
I had tried RECODE and CONVERT but then I was having to delete the old variable and rename the new one which seemed long winded to me.
 
 
 
From: SPSSX(r) Discussion [[hidden email]] On Behalf Of J Sutar
Sent:
15 December 2010 12:45
To:
[hidden email]
Subject:
Re: Changing variable type

 
There are are a number of ways to do this. ALTER TYPE would work if running the latest version of SPSS.
 
Otherwise, you have RECODE option using the keyword CONVERT.
 
And also a COMPUTE command with NUMBER function such as
 
Compute NumbVar=NUMBER(strVar,F8.0).
 
HTH,
Jignesh
On 15 December 2010 12:15, Chris Hunt <crh75@...> wrote:
Hi all,
Can anybody tell me how to change a variable from string to numeric using code.  I have looked through help but to no avail.  The variable in question contains numerical data only but imports as text.
Many thanks
Chris