CONVERT Keyword (RECODE command)

CONVERT recodes the string representation of numbers to their numeric representation.

  • If the keyword CONVERT precedes the value specifications, cases with numbers are recoded immediately and blanks are recoded to the system-missing value, even if you specifically recode blanks into a value.
  • To recode blanks to a value other than system-missing or to recode a string value to a noncorresponding numeric value (for example, ‘0’ to 10), you must specify a recode specification before the keyword CONVERT.
  • RECODE converts numbers as if the variable were being reread using the F format.
  • If RECODE encounters a value that cannot be converted, it scans the remaining value specifications. If there is no specific recode specification for that value, the target variable will be system-missing for that case.

Examples

RECODE #JOB (CONVERT) ('-'=11) ('&'=12) INTO JOB.
  • RECODE first recodes all numbers in the string variable #JOB to numbers. The target variable is JOB.
  • RECODE then specifically recodes the minus sign (the “eleven” punch) to 11 and the ampersand (or “twelve” punch in EBCDIC) to 12. The keyword CONVERT is specified first as an efficiency measure to recode cases with numbers immediately. Blanks are recoded to the system-missing value.
    RECODE #JOB (' '=-99) (CONVERT) ('-'=11) ('&'=12) INTO JOB.
  • The result is the same as in the above example except that blanks are changed to −99.