Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: st: Import multiple excel sheets


From   Michael Betz <betz.40@buckeyemail.osu.edu>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   RE: st: Import multiple excel sheets
Date   Mon, 10 Sep 2012 21:04:41 +0000

Perfect! Thanks Daniel. That gives me what I need to write the loop.

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of daniel klein
Sent: Friday, September 07, 2012 12:34 PM
To: statalist@hsphsun2.harvard.edu
Subject: Re: st: Import multiple excel sheets

Mike,

have a look at the saved results from -import excel- with -describe-
option. The number (and names) of the sheets of each file is saved in
r().

Best
Daniel

-- 
Hi all,

I need to import many excel files that each have multiple worksheets
and then append them. I have about 51 files that vary in the number of
sheets each one has. They are named 'file1' file2' 'file3'...ect. Each
sheet is named 'Unit' Unit1' 'Unit2'...ect (Note the first sheet
doesn't have a number in its name). I've been thinking about the
problem in the following manner, but got stuck because I'm not sure
how to import the multiple sheets from each file when each file has a
different number of sheets.

forvalues i=1/51{
	import excel "C:\Users\file`i'.xls", sheet("Unit") firstrow case(lower) clear
	if `i'>1 append using "mainfile"
	save "mainfile", replace
	}

Any thoughts?

Thanks,
Mike
*
*   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/



*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index