ARCHIVED: In SPSS, how do I convert between numeric variables and string variables?

This content has been archived, and is no longer maintained by Indiana University. Resources linked from this page may no longer be available or reliable.

In SPSS, to convert a numeric variable to a string variable, use the STRING() function. Since the default variable type in SPSS is numeric, you need to define your string variable in advance. Consider the following example:

  STRING str (A8).
  COMPUTE str = STRING(num, F2.0).
  EXECUTE.

In the example above, A8 indicates a string variable eight characters long, and F2.0 is the format of output values of variable num. For example, F8.4 fills four zeroes after the decimal point when the numeric variable num is an integer.

To convert a string variable to a numeric variable num, use the NUMBER() function, for example:

  COMPUTE num = NUMBER(str, F8.2).
  EXECUTE.

If you have questions about using statistical and mathematical software at Indiana University, contact Research Analytics.

This is document aoym in the Knowledge Base.
Last modified on 2018-01-18 14:00:50.

Contact us

For help or to comment, email the UITS Support Center.