Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Problems with insheet within a foreach loop


From   "Paul McCabe" <[email protected]>
To   [email protected]
Subject   st: Problems with insheet within a foreach loop
Date   Wed, 23 Jul 2008 13:15:25 +0100

Dear Statlisters

I am trying to read file names from a folder prior to processing and appending.

My local appears to be picking up the names - see log part A below.
The foreach loop appears to be having problems with insheet-ing -
specifically an r(601) error message that a file is not found - see
log part B below.
The source file is where it should be and I'm blank.

Any ideas what may be causing this?

Many thanks
Paul


log A

. local mort: dir "P:/Public Health/Vital Statistics_R/ONS Monthly PH
Files/ONS Monthly PH Mortality Files/2007-08/Raw Data/texts/" files
"*.txt"

. foreach file of local mort {
  2.         di "`file'"
  3.
      }
p5a8ap07.txt
p5a8au07.txt
p5a8de07.txt
p5a8fe08.txt
p5a8ja08.txt
p5a8jl07.txt
p5a8jn07.txt
p5a8mr08.txt
p5a8my07.txt
p5a8no07.txt
p5a8oc07.txt
p5a8se07.txt

.
end of do-file

log B
. local mort: dir "P:/Public Health/Vital Statistics_R/ONS Monthly PH
Files/ONS Monthly PH Mortality Files/2007-08/Raw Data/texts/" files
"*.txt"

. foreach file of local mort {
  2.         di "`file'"
  3.         insheet using `file'
  4.         clear
  5.         di "`file'"
  6.         }
p5a8ap07.txt
(87 vars, 171 obs)               **This insheet appears to work
p5a8ap07.txt
p5a8au07.txt
file p5a8au07.txt not found   **This one doesn't
r(601);

end of do-file
r(601);
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index