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: semicolon in local, under delimit ;
From 
 
David Kantor <[email protected]> 
To 
 
[email protected] 
Subject 
 
Re: st: semicolon in local, under delimit ; 
Date 
 
Fri, 07 Feb 2014 12:17:57 -0500 
Hello.
Thanks to both Nicks for the suggestions.
I note that the technique of building up a local macro with pieces in 
" ", as in the response from Nick Cox, works fine under -delimit ;-, 
even with embedded semicolons, as long as you don't use compound quotes.
Also the command inside the loop,
   local foo `" `foo' "`f`j''" "'
works fine under -delimit ;-, even with embedded semicolons -- noting 
that during its iteration it would appear to expand to include 
compound quotes and embedded semicolons.
The explanation is that the command is parsed once, prior to the 
iterations; the embedded semicolon does not appear at that stage.
The suggestion by Nick Winter to use /// is helpful in some 
situations, but it doesn't work in the middle of a macro evaluation.
Nor is /*
*/
Thanks
--David
At 05:34 PM 2/6/2014, you wrote:
This recipe shows one technique for building up a local macro with
pieces in " ":
local foo
local f1 just waking up
local f2 stretch and groan
local f3 stuff
local f4 breakfast
forval j = 1/4 {
    local foo `" `foo' "`f`j''" "'
}
mac li
_foo:            "just waking up" "stretch and groan" "stuff" "breakfast"
_f4:            breakfast
_f3:            stuff
_f2:            stretch and groan
_f1:            just waking up
Nick
[email protected]
On 6 February 2014 21:32, David Kantor <[email protected]> wrote:
> I find that if I have...
>
> #delimit ;
>
> local m1  "abc;def";
> disp "`m1'";
>
> -- that works as expected, but...
>
> local m2  `"abc;def"';
> disp "`m2'";
>
> chokes on the -local- command. It appears to stop at the first semicolon,
> and renders an "invalid syntax" error.
> Apparently, the embedded semicolon signals the end of the command.
>
> Notice that this happens with compound quotes, but not with simple quotes.
>
> Does anyone have experience with this? -- a solution?
> I need to use compound quotes because the actual situation has a macro with
> components that have embedded spaces -- so that -foreach- will pick up
> segments of the macro having embedded spaces. Thus, for example,
> local m3 `""first item" "second item""'
> --is constructed so that -foreach- yields two pieces:
> first item
> second item
> --rather than four pieces:
> first
> item
> second
> item
>
> And the real-life application is too big to put on one line, so I use
> #delimit ;.
> It worked fine until I added an item having an embedded semicolon.
>
> I use Stata 10. (I plan to upgrade soon.)
[...]
*
*   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/