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 on April 23, 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 excel needs hardcoded first character


From   daniel klein <klein.daniel.81@googlemail.com>
To   statalist@hsphsun2.harvard.edu
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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index