Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
st: import excel needs hardcoded first character
From
"Feiveson, Alan H. (JSC-SK311)" <[email protected]>
To
"[email protected]" <[email protected]>
Subject
st: import excel needs hardcoded first character
Date
Fri, 31 Aug 2012 11:17:45 -0500
Hello - I am trying to import an excel file with the file name as an argument.
In the first example below, the first character of the file name is hard-coded as "t", and I supply the rest of the file name as an argument `fn'. The name of my file is "test.xlsx". This works (see below).
args fn listnumber
import excel using d:\docume~1\afeiveso\mydocu~1\excel\t`fn',clear first case(lower)
. run global_list est.xlsx 1
[ no errors]
Now in the second example, I try to use the entire file name as an argument. This does not work.
args fn listnumber
import excel using d:\docume~1\afeiveso\mydocu~1\excel\`fn',clear first case(lower)
. run global_list test.xlsx 1
file d:\docume~1\afeiveso\mydocu~1\excel not found
r(601);
With trace on, it appears that Mata ignores the filename and treats it as missing. Any ideas of what's going on here?
Thanks
Al Feiveson
. run global_list test.xlsx 1
-------------------------------------------------------------------------- begin import ---
- version 12
- gettoken subcmd 0 : 0
- if `"`subcmd'"' == "exc" {
= if `"excel"' == "exc" {
ImpExcel `0'
}
- if `"`subcmd'"' == "exce" {
= if `"excel"' == "exce" {
ImpExcel `0'
}
- if `"`subcmd'"' == "excel" {
= if `"excel"' == "excel" {
- ImpExcel `0'
= ImpExcel using d:\docume~1\afeiveso\mydocu~1\excel,clear first case(lower)
--------------------------------------------------------------- begin import.ImpExcel ---
- version 12
- scalar ImpExcelCleanUp = -1
- capture noi import_excel `0'
= capture noi import_excel using d:\docume~1\afeiveso\mydocu~1\excel,clear first case(low
> er)
---------------------------------------------------------------- begin import_excel ---
- version 12
- if ("`c(excelsupport)'" != "1") {
= if ("1" != "1") {
dis as err `"import excel is not supported on this platform."'
exit 198
}
- gettoken filename rest : 0, parse(" ,")
- gettoken comma : rest, parse(" ,")
- if (`"`filename'"' != "" & (trim(`"`comma'"') == "," | trim(`"`comma'"') == "")) {
= if (`"using"' != "" & (trim(`"d:\docume~1\afeiveso\mydocu~1\excel"') == "," | trim(`"
> d:\docume~1\afeiveso\mydocu~1\excel"') == "")) {
local 0 `"using `0'"'
}
- capture syntax using/, DESCribe
- if _rc {
- capture syntax using/ [, SHeet(string) CELLRAnge(string) FIRSTrow ALLstring case(stri
> ng) locale(string) clear]
- if _rc {
syntax [anything(name=extvarlist id="extvarlist" equalok)] using/ [, SHeet(string) CE
> LLRAnge(string) FIRSTrow ALLstring locale(string) clear]
}
- }
- mata : import_excel_import_file()
file d:\docume~1\afeiveso\mydocu~1\excel not found
------------------------------------------------------------------ end import_excel ---
- nobreak {
- local rc = _rc
- if `rc' {
= if 601 {
- if ImpExcelCleanUp >= 0 {
mata : import_excel_cleanup()
}
- }
- }
- scalar drop ImpExcelCleanUp
- exit `rc'
= exit 601
----------------------------------------------------------------- end import.ImpExcel ---
}
---------------------------------------------------------------------------- end import ---
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/