SPSS selecting type as string when should be numeric

Moderators: statman, Analyst Techy, andris, Fierce, GerineL, Smash

spssuser01
Posts: 3
Joined: Sun Dec 13, 2015 11:06 am

SPSS selecting type as string when should be numeric

Postby spssuser01 » Sun Dec 13, 2015 11:14 am

I have some data with just over 3000 variables that I load in through a CSV file.

I'm making changes to it outside of SPSS and load it in on a regular basis to do some work.

Whenever I do load it in, it keeps selecting string for several field types and I have to manually change it to numeric.

I've checked the data and there is nothing but numbers so I can't seem to figure out why it's selecting string.

It's quite annoying as I have to change around 100 of these fields to numeric and it's quite time consuming/slowing down my work.

I'm sure there are several ways to do this better (My SPSS skills are very limited as I have just started using it so excuse my ignorance!)

Does anyone have any ideas on how I could better do this?

Thanks.
statman
Administrator
Posts: 2750
Joined: Tue Jun 12, 2007 12:08 pm
Location: Florida, USA

Re: SPSS selecting type as string when should be numeric

Postby statman » Sun Dec 13, 2015 1:17 pm

As you import, you should be given a per variable option to set its parameters but .....
See the note below

NOTE: Please read the Posting Guidelines and always tell us your OS, the SPSS version and information about your study and data!

Statman
Statistical Services
spssuser01
Posts: 3
Joined: Sun Dec 13, 2015 11:06 am

Re: SPSS selecting type as string when should be numeric

Postby spssuser01 » Mon Dec 14, 2015 2:49 am

Hi, yes sorry. I'm using windows 8 and SPSS version 21. I can't talk too much about the data due to it being work but basically I have a bunch of predictor variables which are all numeric and the target is a binary outcome 1 or 0. I'm using a binary logistic regression to model.

The problem with selecting per variable is as I mentioned there are over 3000 variables, it's too time consuming to go in each time and select each variable and change it to numeric.

The reason is that the data is generated outside in a separate program and as new variables are added in this obviously makes new field names so I have to manually select which variables are numeric each time. It happens to maybe 100 of the variables.

SPSS says it determines the type based on the first 200 rows of data, but the data in all the rows for these variables are strictly numeric.

As I mentioned I don't know too much about SPSS. Is it possible to write a loop in the syntax that would load in all the data or do you have to define each variable individually? (Which isn't an option as I mentioned the data changes a bit so I don't really have static field names at the moment)
GerineL
Moderator
Posts: 1477
Joined: Tue Jun 10, 2008 4:50 pm

Re: SPSS selecting type as string when should be numeric

Postby GerineL » Mon Dec 14, 2015 8:58 am

you can also do it by syntax:

Code: Select all

compute var1n = number(variable1, f8.2).
compute var2n = number(variable2, f8.2).
execute.
if you just place your variable names in one column in excel, and the rest of the syntax in other columns, you can easily create such a syntax for 3000 variables in a few minutes using drag or copy paste.
spssuser01
Posts: 3
Joined: Sun Dec 13, 2015 11:06 am

Re: SPSS selecting type as string when should be numeric

Postby spssuser01 » Wed Dec 16, 2015 10:46 am

Does anyone know how SPSS determines whether a field is a string or not?

The fields it's guessing are strings are all fractions and most below 1, ie 0.435, -0.7643 etc... I think that may be the problem, does anyone know for sure?
GerineL
Moderator
Posts: 1477
Joined: Tue Jun 10, 2008 4:50 pm

Re: SPSS selecting type as string when should be numeric

Postby GerineL » Wed Dec 16, 2015 1:29 pm

For me it usually works fine, so maybe something in the source?

Who is online

Users browsing this forum: No registered users and 2 guests

cron