By Ruben Geert van den Berg on July 11, 2017 under Blog.

SPSS ALTER TYPE Reporting Wrong Values?

SPSS Alter Type Bug

In some cases, ALTER TYPE in SPSS version 24 seems to report incorrect altered values when converting a string to a numeric value. This results in messed up data while SPSS reports that everything is fine. Let's try and replicate the problem with the example below.


We imported some .csv data in which some numeric values were flagged with an “a”. This indicates that these were estimated rather than measured values. Due to these flags, some variables were imported as string variables. The syntax below recreates a microsample from these data.

*Create mini test data.

data list free/s1 (a2).
begin data
'' '1' '1a' '2' '2a' '3' '3a' '4' '4a' '5' '5a'
end data.


SPSS Alter Type Bug Data View Before

Convert to Numeric with ALTER TYPE

We'll now convert our string to a numeric variable with the syntax below. Since our variable seems to hold only single digit integers, we chose to convert it into the f1 format. As an extra safety check, we'll inspect which original values are converted into which new values.

*ALTER TYPE and report altered values.

alter type s1(f1)
/print alteredvalues.


SPSS Alter Type - Altered Values Table

This table suggests that all variables have been converted as desired. It seems SPSS made the right guess that string value 1a should be changed to 1. Furthermore, only empty string values result in system missings after the conversion. Mission accomplised?

Data View after ALTER TYPE

SPSS Alter Type Bug Data View After

At first glance, everything looks great. Ok, we do have quite some system missing values after the conversion but those were all empty string values. Right?
But let's take another quick look at our original data: our flagged values weren't converted as reported in the altered values table. They all result in system missing values.
With just 1 variable and 11 cases, we immediately see the problem. However, the actual data contained some 40,000 records and it was more or less by accident that I stumbled upon the issue.

Which SPSS Versions?

My students tried to replicate the issue in SPSS versions 18 and 22. Neither version reported incorrect values because the altered values tables were empty -for this example at least.
Perhaps the /PRINT ALTEREDVALUES subcommand was introduced in version 23 or 24 but the CSR does not mention anything about it.

Thanks for reading!

Related Tutorials

How to Convert String Variables into Numeric Ones?

Convert SPSS string variables into numeric ones the right way. Quickly master the trick with this step-by-step example with downloadable practice data. Read more

SPSS Variable Types and Formats Tutorial

Understanding SPSS variable types and formats allows you to get things done fast and reliably. Getting a grip on types and formats is not hard. However, the way they've been implemented in SPSS is very, very confusing. This tutorial aims at taking away this confusion and putting the user back into control. Read more

Comment on this Tutorial

*Required field. Your comment will show up after approval from a moderator.

This Tutorial has 6 Comments