Announcement

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

  • remove ;

    Dear All, I found this question here. The data is
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float num str120 IPC
    1 "B01D53/86(2006.01)I;B01D53/56(2006.01)I"                                         
    2 "B01J23/30(2006.01)I;B01J35/10(2006.01)I;"                                        
    3 "B01J23/92(2006.01)I;B01J23/30(2006.01)I;B01J38/02(2006.01)I;B01J38/04(2006.01)I;"
    end
    If IPC ends with ";" (num=2,3), how can I delete it? Thanks.
    Ho-Chuan (River) Huang
    Stata 19.0, MP(4)

  • #2
    try this:
    Code:
    gen leng=length(IPC)
    replace IPC=substr(IPC,1,leng-1) if substr(IPC,-1,1)==";"
    drop leng

    Comment


    • #3
      An alternative method:

      Code:
      gen want = ustrregexrf(IPC, "^(.*);$", "$1")

      Comment


      • #4
        Dear @Rich Goldstein and @Leonardo Guizzetti, Thanks a lot for your helpful syggestions.

        Ho-Chuan (River) Huang
        Stata 19.0, MP(4)

        Comment


        • #5
          Also
          Code:
          replace IPC = ustrregexrf(IPC, ";$", "")

          Comment


          • #6
            Dear @Rich Goldstein, @Leonardo Guizzetti, and @William Lisowski: Thanks a lot for your helpful suggestions.
            Last edited by River Huang; 18 Sep 2022, 19:11.
            Ho-Chuan (River) Huang
            Stata 19.0, MP(4)

            Comment


            • #7
              Thanks a lot, William.
              Ho-Chuan (River) Huang
              Stata 19.0, MP(4)

              Comment

              Working...
              X