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]

st: Why does Stata return a syntax error when a quoted item containing spaces is the first element in a macro?


From   Aaron Kirkman <[email protected]>
To   [email protected]
Subject   st: Why does Stata return a syntax error when a quoted item containing spaces is the first element in a macro?
Date   Mon, 17 Jun 2013 16:23:56 -0500

I'm iterating over a macro that contains quoted elements with spaces,
but Stata returns a syntax error when a quoted element is the first
item. The list items are sheet names, e.g. "All Individuals", "<25",
... , "28+". This code:

    local sheets "All Individuals" <25 26 27 28+

returns a syntax (r198) error on the macro declaration. I get the same
error if I use compound quotes:

    local sheets `""All Individuals""' <25 26 27 28+

If I move the quoted item to another position in the list, the macro
declaration is successful and I can iterate over the items properly:

    local sheets <25 "All Individuals" 26 27 28
    foreach sheetname of local sheets {
        display `"`sheetname'"'
    }

I found a similar example on stack overflow
(http://stackoverflow.com/a/10067769):

    local mylist aaa bbb "cc c" dd ee ff
    foreach filename of local mylist {
      display `"`filename'"'
    }

which works in the same fashion and is successful. However, if I move
the quoted item to the beginning of the macro:

    local mylist "cc " aaa bbb dd ee ff

Stata returns the same syntax error as before. How can I set up this
macro in order for Stata to parse it correctly? The "All Individuals"
item needs to be the first item in the macro; otherwise I would move
it elsewhere in the list to bypass the error. Am I escaping the quotes
incorrectly?

I'm using Stata 12 MP on Windows 7 x64.


Thank you,
Aaron
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index