Announcement

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

  • wildcard in string variable

    I'm trying to link different business locations to appropriate zip codes using a do-file. I have business names in a name variable and created a new variable to hold the zipcode. Some of the business names are similar but they have a location indicator at the end such as "Office - Allendale" and "Office-Grand Rapids". I tried using a replace command with an if statement but it doesn't appear that I can use wildcards in that. Is there a way for me to do this? Below is how I'm currently doing it...

    replace zip="49401" if locationname==" Office - Allendale"

    This works for just a few instances but I have a health system with hundreds of entries so trying to avoid having to individually manage each one since they have the embedded location descriptor" Thank you!

  • #2
    It is not clear what you are doing as your description is not precise.
    Allendale may refer to any of the following: https://en.wikipedia.org/wiki/Allendale
    So why the particular zip code is picked is not obvious from the description.

    Most likely you would need to parse the locationname into two parts - descriptive and location, such as "Branch - New Orleans" or "Factory - Pennsylvania". This can be done with split command, or word() function. But one would need to know more about what were the rules for combining the parts into locationname and what are the possibilities for parts. Be careful with the dashes, as they can be occurring inside either part: "sub-station", "Pas-de-Calais".

    Once you have the location specifier that can open an avenue for picking the appropriate zip code.

    Best, Sergiy

    Comment


    • #3
      Sorry I was not clear, I already know from another source the specific address including zip that should go along with the descriptor "Office-Allendale" and am trying to write those to the datafile myself. These datafields did not come through on the original data file that is being shared with me. They only include the descriptor businessname information. In my do file, I'm trying to add that information into the data file with 1 command and then have this available moving forward because I get new data files submitted daily and weekly from various sources. Ultimately, I need to collapse some tracking by zip code.

      I want to replace the zip code from missing to the correct one (which I know and am trying to put into my do-file". I'm hoping for a simple way to use the wildcards in a statement similar to my replace using the if qualifier attempt. I tried to use replace if *Allendale but that was not recognized (perhaps because it did not meet the == requirements(?)

      I hope this better describes what I"m trying to do.

      Comment


      • #4
        Still not clear, but read about the merge command, which is typically what you would use if you need to bring some static information (such as office zip code) to dynamic data file (such as transactions performed in a specific office).

        Comment

        Working...
        X