Announcement

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

  • Appending excel files - Error r(601)

    Hi. I am trying to append all excel files in a single folder into one big file, but the code below throws the r(601) error. I've made sure that the files have no leading or trailing spaces, so am not sure what is happening. Any help would be great. Thanks.

    Code:
    local filenames: dir "C:\Users\katja\Dropbox\Raw Data"  files "*.xlsx*"
    
    foreach f of local filenames {
    import excel using `"`f'"'
    gen source = `"`f'"'
    display `"Appending `f'"'
    append using `building'
    save `"`building'"', replace
    }
    
    export excel using 1_large_excel_file.xlsx, replace

  • #2
    Katja/Scott/Rick:

    What is inside the local macro building?

    You need to worry about spaces within filenames too. That applies to

    Code:
     
     append using `building'
    which would be safer as
    Code:
    append using "`building'"
    Otherwise the problem lies in the filenames you have, which you are not showing us.

    Comment


    • #3
      Hi Nick Cox. Scott here. Thanks for the quick response. Unfortunately the above didn't work. The file names are: alwal_oct22_feb23, gmrv_oct22_feb23, kar_oct22_feb23, kvc_oct22_feb23, mtc_oct22_feb23....

      Alternately, is there any other way to do it?
      Last edited by Scott Rick; 25 Mar 2023, 05:07.

      Comment


      • #4
        You'd also get the same problem if you were working in another directory or folder. You told the dir to look in a particular folder, but if you are not working in that folder, import excel will necessarily look in the current one, as shown by pwd.

        Comment


        • #5
          I'm not sure I follow. I am working in the folder that dir is set to:
          "C:\Users\katja\Dropbox\Raw Data"

          Comment


          • #6
            That aspect is fine, then, but I am almost out of ideas, except to note that you haven't answered what is in building? As in please show the result of


            Code:
            display "`building'"
            Note that that macro must be defined in the same place as the rest of your code.

            Comment


            • #7
              Cross-posting: see concurrent thread. https://www.statalist.org/forums/for...a-folder/page2

              Please follow that if interested.

              Comment

              Working...
              X