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   "Feiveson, Alan H. (JSC-SK311)" <[email protected]>
To   "[email protected]" <[email protected]>
Subject   RE: st: import excel needs hardcoded first character
Date   Fri, 31 Aug 2012 12:52:12 -0500

Ah yes, I forgot about this! Thanks Daniel and Nick.

Al

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Nick Cox
Sent: Friday, August 31, 2012 12:08 PM
To: [email protected]
Subject: Re: st: import excel needs hardcoded first character

Yet another reference is

SJ-8-3  pr0042  . . . . . . .  Stata tip 65: Beware the backstabbing backslash
        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox
        Q3/08   SJ 8(3):446--447                                 (no commands)
        tip to use forward slash instead of backslash for
        directory and file names

Nick

On Fri, Aug 31, 2012 at 5:33 PM, daniel klein
<[email protected]> wrote:

> 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/

*
*   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