Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to change "769X" into "7690"

    Hi,

    One variable has numeric values and non-numeric value ("X") together. For example, many observations are just numbers (e.g., "7990"), but several observations include "X", such as "769X".

    Is there any way to change values with "X" into number - e.g., "769X" into "7690"? Thank you!

    Best,

  • #2
    Firstly make sure your variable (below I use yourvariable as proxy) is stored as string
    Code:
    display "`:type yourvariable'"
    Then use subinstr() function to substitute 0 for X:
    Code:
    replace yourvariable=subinstr(yourvariable,"X","0",.)
    destring yourvariable, replace

    Comment


    • #3
      Dear Chen Samulsion,

      Thank you so much for your help! The commands worked.

      Comment


      • #4
        Jennifer Yoo

        in case you are dealing with ISBNs, the X may occur only in the last position as a check digit in base eleven. It is redundant and may be dropped (and recomputed later if needed). Replacing it with a zero, however, will create an invalid ISBN.

        Best, Sergiy

        Comment

        Working...
        X