How to convert multiple string varibles into numeric in SPSS?

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

How to convert multiple string varibles into numeric in SPSS?

behkami
My Excel file (xlsx) contains more than 1200 columns. I tried to open it using the SPSS version 17.01 but the following error came up: "Error Starting the Java Virtual Machine; unable to open file; "FILE NAME"".
I had no choice but copy/paste all the data from Excel into SPSS. But when I do it, all the variables are changed into string (on variables page).
Is there a way to convert multiple string variables into numeric using a single command?
Any suggestions would be highly appreciated.

Behkami M.D
PhD student in Immunology
Reply | Threaded
Open this post in threaded view
|

Re: How to convert multiple string variables into numeric in SPSS?

Jon K Peck
SPSS should be able to read the file directly - maybe your version is too old to support Excel 2007, but you can use the ALTER TYPE command to change the type of all the variables.  The pasted cells probably contained some nonnumeric values, which forced the types to be string.

Jon Peck
Senior Software Engineer, IBM
[hidden email]
new phone: 720-342-5621




From:        behkami <[hidden email]>
To:        [hidden email]
Date:        07/11/2011 08:55 AM
Subject:        [SPSSX-L] How to convert multiple string varibles into numeric in              SPSS?
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




My Excel file (xlsx) contains more than 1200 columns. I tried to open it
using the SPSS version 17.01 but the following error came up: "Error
Starting the Java Virtual Machine; unable to open file; "FILE NAME"".
I had no choice but copy/paste all the data from Excel into SPSS. But when I
do it, all the variables are changed into string (on variables page).
Is there a way to convert multiple string variables into numeric using a
single command?
Any suggestions would be highly appreciated.

Behkami M.D
PhD student in Immunology


--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/How-to-convert-multiple-string-varibles-into-numeric-in-SPSS-tp4574076p4574076.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


Reply | Threaded
Open this post in threaded view
|

Re: How to convert multiple string variables into numeric in SPSS?

Garry Gelade

If your SPSS version does not support xlsx, simply save the .xlsx file to .xls in Excel, and then read in the .xls file.

 

Garry Gelade

 

From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Jon K Peck
Sent: 11 July 2011 08:04
To: [hidden email]
Subject: Re: How to convert multiple string variables into numeric in SPSS?

 

SPSS should be able to read the file directly - maybe your version is too old to support Excel 2007, but you can use the ALTER TYPE command to change the type of all the variables.  The pasted cells probably contained some nonnumeric values, which forced the types to be string.

Jon Peck
Senior Software Engineer, IBM
[hidden email]
new phone: 720-342-5621




From:        behkami <[hidden email]>
To:        [hidden email]
Date:        07/11/2011 08:55 AM
Subject:        [SPSSX-L] How to convert multiple string varibles into numeric in              SPSS?
Sent by:        "SPSSX(r) Discussion" <[hidden email]>





My Excel file (xlsx) contains more than 1200 columns. I tried to open it
using the SPSS version 17.01 but the following error came up: "Error
Starting the Java Virtual Machine; unable to open file; "FILE NAME"".
I had no choice but copy/paste all the data from Excel into SPSS. But when I
do it, all the variables are changed into string (on variables page).
Is there a way to convert multiple string variables into numeric using a
single command?
Any suggestions would be highly appreciated.

Behkami M.D
PhD student in Immunology


--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/How-to-convert-multiple-string-varibles-into-numeric-in-SPSS-tp4574076p4574076.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

Reply | Threaded
Open this post in threaded view
|

Re: How to convert multiple string varibles into numeric in SPSS?

Albert-Jan Roskam
In reply to this post by behkami
Hello,

You can save the file as csv in Excel, then open it in Spss. Check that the columns don't contain any unintended characters. If there is e.g. a dot/period in one of the cells, the corresponding column will be a character var.

This could be  the case with 'dirty' excel sheets. At least Spss handles this nicely (cf. RODBC in R).

Cheers!!
Albert-Jan

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a fresh water system, and public health, what have the Romans ever done for us?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

--- On Mon, 7/11/11, behkami <[hidden email]> wrote:

From: behkami <[hidden email]>
Subject: [SPSSX-L] How to convert multiple string varibles into numeric in SPSS?
To: [hidden email]
Date: Monday, July 11, 2011, 8:53 AM

My Excel file (xlsx) contains more than 1200 columns. I tried to open it
using the SPSS version 17.01 but the following error came up: "Error
Starting the Java Virtual Machine; unable to open file; "FILE NAME"".
I had no choice but copy/paste all the data from Excel into SPSS. But when I
do it, all the variables are changed into string (on variables page).
Is there a way to convert multiple string variables into numeric using a
single command?
Any suggestions would be highly appreciated.

Behkami M.D
PhD student in Immunology


--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/How-to-convert-multiple-string-varibles-into-numeric-in-SPSS-tp4574076p4574076.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
To manage your subscription to SPSSX-L, send a message to
LISTSERV@... (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: How to convert multiple string varibles into numeric in SPSS?

behkami
Thank you soooooooooo much Albert-Jan. It was really helpful.   
Reply | Threaded
Open this post in threaded view
|

Re: How to convert multiple string varibles into numeric in SPSS?

David Marso
Administrator
In reply to this post by behkami
Hmmm,  By chance do you have fieldnames in the first row and picking them up in the "copy/paste"?  If so then OF COURSE everything is going to show up as a string.
Have no idea why the "open" failed.

behkami wrote
My Excel file (xlsx) contains more than 1200 columns. I tried to open it using the SPSS version 17.01 but the following error came up: "Error Starting the Java Virtual Machine; unable to open file; "FILE NAME"".
I had no choice but copy/paste all the data from Excel into SPSS. But when I do it, all the variables are changed into string (on variables page).
Is there a way to convert multiple string variables into numeric using a single command?
Any suggestions would be highly appreciated.

Behkami M.D
PhD student in Immunology
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: How to convert multiple string varibles into numeric in SPSS?

Jarrod Teo-2

Hi Behkami,

 

I am not sure if someone had answered you on converting a set of string variables into numeric question part.

 

Assuming that your data is as follows.

 

1st scenario:

 

 v1 v2 v3 v4 

 1   1   1  1 

 1   1   1  1 

 1   1   1  1 

 1   1   1  1  

 

Then the syntax to convert the string numbers, v1 v2 v3 v4, into numerical variables will be as follows:

 

do repeat x1=n1 to n4

/x2=v1 to v4.

 

compute x1=number(x2,f8).

 

end repeat.

exe.

 

The f8 in function of the compute reads the number of string values you want to convert from the original string variables.

 

 

2nd scenario:

 

 v1 v2 v3 v4 

 a   a   a  a 

 a   a   a  a 

 a   a   a  a 

 a   a   a  a 

 

 

recode v1 ('a'=1) into n1.

crosstab v1 by n1.

 

You will have to do it one by one by doing a copy and paste of the above syntax for v2 to v4. This is because it is always a good habit to check your recode to see if you have recoded all the values from your original variable.

 

Warmest Regards

Dorraj Oet


>

>
> behkami wrote:
> >
> > My Excel file (xlsx) contains more than 1200 columns. I tried to open it
> > using the SPSS version 17.01 but the following error came up: "Error
> > Starting the Java Virtual Machine; unable to open file; "FILE NAME"".
> > I had no choice but copy/paste all the data from Excel into SPSS. But when
> > I do it, all the variables are changed into string (on variables page).
> > Is there a way to convert multiple string variables into numeric using a
> > single command?

> > Any suggestions would be highly appreciated.
> >
> > Behkami M.D
> > PhD student in Immunology
> >
>
>
> --
> View this message in context: http://spssx-discussion.1045642.n5.nabble.com/How-to-convert-multiple-strin! g-varibles-into-numeric-in-SPSS-tp4574076p4580036.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