Announcement

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

  • #16
    Hi Clyde,

    My apology. Following your instructions and making several trials, still no progress at all.
    The code is error-free but no data appended.

    Thank you.
    CAPI Specialist
    Data Manager

    Comment


    • #17
      Because I do not have, and cannot reasonably recreate a file structure like the one you are working with, my ability to further help with this is limited. Here's what I suggest you do:
      [/code]
      cd "C:\Users\2023-2024 SF1"
      local return_to `c(pwd)'
      clear
      tempfile schroom
      save `schroom', emptyok
      local folders `" "Tawi-Tawi" "Basilan" "Sulu" "'
      foreach F of local folders {
      local subfolders: dir `"`F'"' dirs "*.xls"
      display `"`subfolders'"'
      foreach s of local subfolders {
      cd `"`F'/`s''
      pwd

      // EMBED CODE TO PROCESS SINGLE FOLDER HERE
      local allfiles: dir "." files "*.xls" // OR WHATEVER IS THE FILE NAME PATTERN
      display `"`allfiles'"'
      foreach f of local allfiles {
      display `"`f'"'
      import excel "`f'", cellrange(A3:AM4) clear
      local school_id = F[1]
      import excel "`f'", cellrange(A5) firstrow case(lower) clear
      gen schoolid = `school_id'
      gen source = subinstr(`"`f'"',".xls","",.)
      count
      append using "`schroom'"
      count
      save "`schroom'", replace
      }
      cd `"`return_to'"'
      }
      }
      [/code]
      Lines in bold face are either modified from previous post or are new. Two lines were modified because they contained surplus quotes. I don't think the surplus quotes are the cause of the problem, and probably they are harmless, but best to remove all spotted irregularities. With the added -display-, -pwd-, and -count- commands the output should enable you to see whether you are in fact capturing the correct filenames and directory paths in the local macros, and whether the -import excel- commands are actually bringing data into the file. When you see an output that doesn't match what should be happening, that will give you a clue that the immediately preceding lines have a problem somewhere. From there you may be able to fix the problem yourself, or, if more help is needed, showing the output at the point where it goes awry will make it easier to try to spot the issue.

      Comment

      Working...
      X