Bookmark and Share

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]

Re: st: import excel needs hardcoded first character


From   daniel klein <[email protected]>
To   [email protected]
Subject   Re: st: import excel needs hardcoded first character
Date   Fri, 31 Aug 2012 18:33:04 +0200

Al,

the problem has nothing to do with -import excel-. Stata interprets
the backslash (\) used as an escape character, causing a so-called
"delayed macro substitution". For more information read one of

http://www.stata.com/support/faqs/programming/backslashes-and-macros/
https://profiles.google.com/118088982695968835795/buzz/EoErh7tnVoq
http://enoriver.net/index.php/2011/02/10/delayed-macro-substitution/

Here is a short demonstration

loc foo foobar
di "\`foo'" // displays "`foo'"
di "`foo'" // displays "foobar"

Change

[...] \`fn',clear first case(lower)

to

[...]/`fn',clear first case(lower)

Best
Daniel

-- 
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?
*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index