Announcement

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

  • subinstr function

    I have the following dataset

    Code:
    CID9    CID10
    E891.9    X00.6
    E891.9    X00.7
    E891.9    X00.8
    E891.9    X00.9
    E892    X01.0
    E892    X01.1
    E892    X01.2
    E892    X01.3
    E892    X01.4
    E892    X01.5
    E892    X01.6
    E892    X01.7
    E892    X01.8
    E892    X01.9
    E893.0    X05.0
    E893.0    X05.1
    E893.0    X05.2
    E893.0    X05.3
    E893.0    X05.4
    E893.0    X05.5
    E893.0    X05.6
    E893.0    X05.7
    E893.0    X05.8
    E893.0    X05.9
    I would like to remove all the periods from both of the variables. However, when I try the function -subinstr- below, it does not work. Does anyone know what I am doing wrong? Thank you!
    Code:
    . gen CID9noperiod = subinstr(CID9,".","")
    invalid syntax
    r(198);
    
    .

  • #2
    The subinstr() function requires four arguments. You are missing the fourth argument, which is the number of occurrences (counting from the beginning of the string) to be replaced. If you want to remove them all, you can specify . as the value for the last argument. So it can be "missing value" but it cannot be omitted.

    Code:
    gen CID9noperiod = subinstr(CID9, ".", "", .)

    Comment


    • #3
      I was going to write what Clyde said. But it took me a few minutes to replicate your data because you didn't use dataex, and I hesitated to post when I couldn't replicate. Please use dataex in the future, even for trivial stuff?

      Comment

      Working...
      X