banner



How To Change The Datatype Of Column From String To Continuous In Spss

SPSS Alter TYPE command is mainly used for converting string variables to numeric variables. Nevertheless, it has other interesting applications besides. This tutorial quickly walks you through those, pointing out some pitfalls, tips and tricks along the way.
You can follow along past downloading and opening holidays.sav but y'all do demand SPSS version 16 or higher for using ALTER Type.

SPSS ALTER TYPE Command Data Screenshot

SPSS ALTER TYPE Pitfall

Although Change Type is a great option for getting many things done fast, it has one major shortcoming: if it fails to convert one or more than values, it returns organization missing values without throwing whatever warnings or errors.
If this goes undetected, it may severely impairment your data and bias research outcomes. And even if you do notice system missing values resulting from ALTER TYPE, information technology will be hard to runway down what (if anything) went wrong considering the original values are overwritten.

Playing information technology Safe

Nosotros propose 2 basic strategies for playing information technology condom:

  • Always copy your variables earlier converting them. A great tool for cloning many (or all) variables in your data is freely downloadable from Clone Variables.
  • Just run Modify Type on your original variables but check the results for system missings immediately afterwards. If they are present and you don't know why, close your data, rerun you syntax up to the suspicious Change Type control and inspect what values could cause the problem.

SPSS Change TYPE - String to Numeric

We'd like to know the average age of our participants but we tin't calculate it because age is a cord variable in our information. The syntax beneath first copies and converts information technology to a numeric variable. Nosotros can see that no missing values occur in the result past running DESCRIPTIVES; northward is equal to the number of cases in our information.

SPSS ALTER TYPE String to Numeric

SPSS Alter Type Syntax Example i

*1. Cord control for creating new string variable.

string copy_age(a2).

*2. Re-create historic period into new cord variable.

compute copy_age = age.

*3. Convert string to numeric.

alter blazon age(f2).

*4. Check for missing values and average age.

descriptives age.

SPSS ALTER TYPE no missing values

SPSS ALTER TYPE - Cord to Date

We now turn to birthday. This is a string variable and we wish to convert it to a date variable. Now, SPSS date variables are numeric variables holding numbers of seconds that are displayed as normal dates. They have several display options, a quick overview of which is found under appointment format. Note that the string values in birthday correspond to what engagement values await similar if their format is prepare to DATE11. We therefore must specify DATE11 in ALTER TYPE (step 3 below) for converting birthday to a appointment variable.

SPSS Change Blazon Syntax Example ii

*1. Create new string variable for copying birthday.

cord copy_birthday(a11).

*2. Re-create birthday values into new string variable.

compute copy_birthday = altogether.

*3. Convert birthday to appointment variable.

change blazon birthday(date11).

*4. Check for missing values.

descriptives birthday.

SPSS Alter TYPE - Cord to Date

Notation that start and end are also string variables. Their values look like date values displayed as EDATE10. Nosotros'll re-create and convert both of them to appointment variables past the syntax below.

*1. Create two new cord variables.

string copy_start copy_end(a10).

*2. Copy values of showtime and end into new string variables.

compute copy_start = first.
compute copy_end = finish.

*3. Convert both string variables to appointment variables.

alter blazon first end(edate10).

Organization Missing Values from ALTER Type

Annotation that Alter TYPE resulted in a system missing value without whatever alarm or mistake. Fortunately, nosotros copied our variables before converting them and copy_start tells the states that the solar day and month were reversed for 1 case. Because cases take unique id values, we can easily correct the problem past combining Engagement.DMY and IF equally shown in the next syntax example.

SPSS ALTER TYPE command system missing value

*Set correct start date for example with id = 482.

if id = 482 start = date.dmy(15,12,2014).
exe.

SPSS Alter TYPE - Filter

An interesting but picayune known feature of Change Type is converting all variables having a given format. We tin can do and then by specifying an input format, which then acts as a filter: ALTER Blazon affects but variables whose formats match this input format. The example below first addresses all variables just only converts those having an EDATE format.

*Catechumen all variables in the information having an edate format to date11.

change type all (edate = date11).

SPSS Modify TYPE - Modify String Lengths

ALTER Blazon can change the lengths of string variables. For example, the last respondent in our data got married and changed her last proper noun to "Hernandez-Garcia". We can't readily right this: equally nosotros can see in variable view, last_name has an A9 format and can thus hold up to 9 characters.

SPSS ALTER TYPE String Length Insufficient

The syntax beneath solves this past increasing its length with Alter Type.

*1. This doesn't work because new name is also long for A9 format.

if id = 595 last_name = 'Hernandez-Garcia'.
exe.

*2. Increment string length of last_name to (max) 30 characters.

modify blazon last_name(a30).

*3. At present last_name is corrected successfully.

if id = 595 last_name = 'Hernandez-Garcia'.
exe.

Value Labels of Numeric Variable to Cord Variable

Annotation that first_name is a numeric variable in our data. Nosotros can change it to a string variable with ALTER Blazon but this will convert the values (1 through 10) instead of the last names, which are in the value labels. The solution is using VALUELABEL simply the entire procedure requires some manual steps outlined in the syntax below.

*1. Create new cord to pass value labels into.

string tmp(a30).

*2. Pass value labels (final names) into string.

compute tmp = valuelabels(first_name).
exe.

*3. Delete original numeric version.

delete variables first_name.

*4. Rename new variable to old variable name.

rename variables tmp = first_name.

*five. Restore original variable order.

add together files file */go along id first_name all.
exe.

SPSS ALTER TYPE - Minimize String Lengths

A prissy Alter Type trick is minimizing the lengths of all string variables in the data. We can do and then by setting all A formats to AMIN: a special ALTER Blazon keyword denoting the minimum length for each string variable.
In the previous examples, nosotros guessed that 30 characters would exist plenty for first_name and last_name. These lengths are really longer than necessary, causing the size of the information file to increase. Nosotros can easily minimize all string lengths by using the same filter feature: alter type all(a = amin).

SPSS ALTER TYPE minimize string widths

As we see from the result, the minimal required lengths for first_name and last_name are 9 and 16.

Source: https://www.spss-tutorials.com/spss-alter-type-command/

Posted by: bellgunfoop.blogspot.com

0 Response to "How To Change The Datatype Of Column From String To Continuous In Spss"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel