Announcement

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

  • Removing numeric extensions (after "-" from string variable

    I have a string variable with numeric extension, here are a few:

    Var 1
    RB422021-55
    RB092021-69
    RB462021-94

    I wanted to remove the numeric extension, for example remove -55 from RB422021-55 and so on.

    Any help will be appreciated.

    Endeshaw

  • #2
    Code:
    clear
    input str11 var1
    "RB422021-55"
    "RB092021-69"
    "RB462021-94"
    end
    
    gen wanted= ustrregexra(trim(var1), "(.*)(-\d+)$", "$1")
    Res.:

    Code:
    . l
    
         +------------------------+
         |        var1     wanted |
         |------------------------|
      1. | RB422021-55   RB422021 |
      2. | RB092021-69   RB092021 |
      3. | RB462021-94   RB462021 |
         +------------------------+

    Comment

    Working...
    X