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: 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
Re: 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 20:16:32 -0500
Hi Nick,
That solved the problem; thank you for clarifying it so quickly.
Aaron
On Mon, Jun 17, 2013 at 4:53 PM, Nick Cox <[email protected]> wrote:
> If you want " " as inner delimiters, you need `" "' as outer delimiters.
>
> local sheets `" "All Individuals" <25 26 27 28+ "'
>
> The outermost delimiters must always be all inclusive whenever they are shown.
>
> Nick
> [email protected]
>
>
> On 17 June 2013 22:23, Aaron Kirkman <[email protected]> wrote:
>> 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.
>>
> *
> * 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/
*
* 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/