Announcement

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

  • Splitting strings of different types in one variable

    For the variable industry, which is 6-digit string, is there a short method to convert it into the desired variable as illustrated below? I know how to do this but it involves a lot of splitting string, creating temp files and then appending. It would be great if there were an easier method.
    industry desired
    113/// 113
    1141// 1141
    1142// 1142
    42191/ 42191
    42192/ 42192
    42193/ 42193
    42194/ 42193

  • #2
    Code:
    split industry, parse(/) destring

    Comment


    • #3
      Wow. That's amazing. Thanks.

      Comment


      • #4
        Or

        Code:
        gen desired = real(subinstr(industry, "/", "", .))
        Code:
        gen desired = real(substr(industry, 1, strpos(industry, "/")-1))

        Comment


        • #5
          Or use destring.

          Comment

          Working...
          X