Announcement

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

  • How to delete character variable containing specific word?

    Let's say I have an example dataset:
    Type Extended Name
    70135M
    ALV INFRASTRUCTURE DEVELOPMENT INVESTMENT
    68774U
    VIETINBANK SECURITIES INVESTMENT TRUST ABCDE
    51656P
    VIETNAM DAIRY PRODUCTS DUPL ABCDE
    I want to create a piece of code that will eliminate variables whose names contain the words "INVESTMENT TRUST" and "DUPL.". In the example above, the second and the third variables are eliminated. Type is the specific assigned code for a firm

    Thanks in advance!





  • #2
    Code:
    drop if regexm(Extended Name,"INVESTMENT TRUST|DUPL")

    Comment


    • #3
      Originally posted by Øyvind Snilsberg View Post
      Code:
      drop if regexm(Extended Name,"INVESTMENT TRUST|DUPL")
      Dear @Øyvind Snilsberg

      It seems that it works even these string are a part of a word. E.g., this code will drop the firm has name "VIETNAM DAIRY PRODUCTS DUPLSSSSS ABCDE" or "VIETNAM DAIRY PRODUCTS SSSSDUPL ABCDE"
      Could you please help me to adjust the code that it only drop "VIETNAM DAIRY PRODUCTS DUPL ABCDE" but not "VIETNAM DAIRY PRODUCTS DUPLSSSSS ABCDE" and "VIETNAM DAIRY PRODUCTS SSSSDUPL ABCDE"

      Comment


      • #4
        there are probably better solutions,
        Code:
        drop if Extended Name != subinword(Extended Name,"INVESTMENT TRUST","",.) | Extended Name != subinword(Extended Name,"DUPL","",.)

        Comment


        • #5
          Thank you for your kind helps

          Comment

          Working...
          X