String/numeric conversion functions

NUMBER. NUMBER(strexpr,format). Numeric. Returns the value of the string expression strexpr as a number. The second argument, format, is the numeric format used to read strexpr. For example, NUMBER(stringDate,DATE11) converts strings containing dates of the general format dd-mmm-yyyy to a numeric number of seconds that represent that date. (To display the value as a date, use the FORMATS or PRINT FORMATS command.) If the string cannot be read using the format, this function returns system-missing.

STRING. STRING(numexpr,format). String. Returns the string that results when numexpr is converted to a string according to format. STRING(-1.5,F5.2) returns the string value '-1.50'. The second argument format must be a format for writing a numeric value.

Example

DATA LIST FREE /tel1 tel2 tel3.
BEGIN DATA
123 456 0708
END DATA.
STRING telephone (A12).
COMPUTE telephone=
  CONCAT(STRING(tel1,N3), "-", STRING(tel2, N3), "-", STRING(tel3, N4)).
  • A new string variable, telephone, is declared to contain the computed string value.
  • The three numeric variables are converted to strings and concatenated with dashes between the values.
  • The numeric values are converted using N format to preserve any leading zeros.