Hello,
I am looking to clean a number of datasets currently in excel format. Each excel file has a standard name format and layout, but each file has different sheets within the file. The sheet's names are all from a set (Strawberry RaspberryBlackberry Cherry "ApplePearTree Fruit" blueberry) but not all files have all sheets from the set, so when I loop the command, it will stop when stata can't locate the specified sheet. Is there anyway to avoid this? ie. can I tell stata to just 'skip' the sheets they can't find?
Thank you!
Below is my current Code:
error returned: "worksheet RaspberryBlackberry Retail List 2016 not found"
I am looking to clean a number of datasets currently in excel format. Each excel file has a standard name format and layout, but each file has different sheets within the file. The sheet's names are all from a set (Strawberry RaspberryBlackberry Cherry "ApplePearTree Fruit" blueberry) but not all files have all sheets from the set, so when I loop the command, it will stop when stata can't locate the specified sheet. Is there anyway to avoid this? ie. can I tell stata to just 'skip' the sheets they can't find?
Thank you!
Below is my current Code:
Code:
forvalues i = 0/209 { foreach x in Strawberry RaspberryBlackberry Cherry "ApplePearTree Fruit" blueberry{ clear all import excel "C:\Users\user\Desktop\BerryMobile Analytics\Data\Retail Sheets\Retail Sheets_2016_21_no2020\2016 (May 6 for 209 Days)\All Days 2016\Berrymobile Fruit Retail Sheet Friday May 6 2016 Day `i' of 2016.xlsx", sheet("`x' Retail List 2016") keep A M keep if A == "Today (in)" gen season_day = `i' rename M `x'_total_inventory drop A save "C:\Users\user\Desktop\BerryMobile Analytics\Data\Retail Sheets\Retail Sheets_2016_21_no2020\2016 (May 6 for 209 Days)\All Days 2016_dta\\`i'_`x'_2016.dta", replace } }
error returned: "worksheet RaspberryBlackberry Retail List 2016 not found"
Comment