Announcement

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

  • Importing data

    Hi all,
    I have a folder x containing about 46 .xlsx sheets with unnecessarily long names eg xxxxx yyyyy zzzzz aaaaa - all versions - False - 2023-01-12-06-16-35.xlsx. but xxxx is a common name. How can I import data by only specifying xxxx and part of yy without necessarily having the whole name in the code?

  • #2
    Give two examples of file names please.

    Comment


    • #3
      This may need some tweaking, but should do it.
      Code:
      local counter=1
      local files : dir "<where the files are stored" files "xxxxx*.xlsx"
      foreach file in `files' {
          qui import excel "`file'" , clear
          qui save `file', replace
          //qui save file`counter', replace
          //local counter = `counter'+1
      }

      Comment


      • #4
        Originally posted by Jared Greathouse View Post
        Give two examples of file names please.
        I am sorry the project I am handling does not allow me to share anything. I would've shared this but I'm bound.

        Comment


        • #5
          Originally posted by George Ford View Post
          This may need some tweaking, but should do it.
          Code:
          local counter=1
          local files : dir "<where the files are stored" files "xxxxx*.xlsx"
          foreach file in `files' {
          qui import excel "`file'" , clear
          qui save `file', replace
          //qui save file`counter', replace
          //local counter = `counter'+1
          }
          This works without an error. But the challenge is where does it save the data? I have browsed all directories I used before and was not able to find the saved data sets which I planned to merge into one.

          Comment


          • #6
            the project I am handling does not allow me to share anything
            I do not care. The FAQ says the fact that you're working with confidential information doesn't absolve you from providing an example! It's also unclear what it is you want to do. I know you wish to import the 46 excel files, that's fine, that's cool.

            but where do you go from there? Do you want to merge these side by side? Do you wish to append them/stack them on top of one another? Like i guess this is where I'm confused, so you having provided code and a minimal worked example (yes, with fake data and fake filenames that illustrates your problem) would help a lot here. My guess is that you wanna append them, but I don't know because you didn't say. So could you please explain what you wanna do after you've imported them?

            Comment


            • #7
              Originally posted by Jared Greathouse View Post
              I do not care. The FAQ says the fact that you're working with confidential information doesn't absolve you from providing an example! It's also unclear what it is you want to do. I know you wish to import the 46 excel files, that's fine, that's cool.

              but where do you go from there? Do you want to merge these side by side? Do you wish to append them/stack them on top of one another? Like i guess this is where I'm confused, so you having provided code and a minimal worked example (yes, with fake data and fake filenames that illustrates your problem) would help a lot here. My guess is that you wanna append them, but I don't know because you didn't say. So could you please explain what you wanna do after you've imported them?
              After importing the files I want to merge them side by side.

              Comment


              • #8
                set directory for files in the save command or cd to the desired location.

                Comment


                • #9
                  Originally posted by George Ford View Post
                  set directory for files in the save command or cd to the desired location.
                  Thanks so much. I have edited it and it worked for me.

                  Comment

                  Working...
                  X