Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: one-variable varlist with options includes extraneous comma


From   Jeph Herrin <[email protected]>
To   [email protected]
Subject   Re: st: one-variable varlist with options includes extraneous comma
Date   Tue, 25 Jul 2006 09:21:52 -0400

IIRC `1' is the macro representing the first token in the string following
the program invocation. In your case, the first token is "foo,". Similarly,
`2' should contain the second token, in your case "option(1". Or am I mixing
up my Stata versions?



Michael Manti wrote:
Stata gurus,

If I define a program that can take a one-variable varlist and an optional option, it includes an extraneous comma in `1' if the program is invoked with the option. The extraneous comma does not appear in `varlist'.

The extraneous comma does not appear if the program is invoked without the option. Example (Stata/SE 9.2, Windows):

. program test1
1. syntax varlist(min=1) [, option(numlist)]
2. display "`varlist'"
3. display "`1'"
4. local varlist : subinstr local varlist "," "", all
5. display "Remove extraneous comma from varlist"
6. display "`varlist'"
7. display "`1'"
8. local 1 : subinstr local 1 "," "", all
9. display "Remove extraneous comma from 1"
10. display "`1'"
11. end

.
. display "Sometimes first argument in one-argument varlist includes extraneous comma"
Sometimes first argument in one-argument varlist includes extraneous comma

.
. test1 foo, option(1 1 1)
foo
foo,
Remove extraneous comma from varlist
foo
foo,
Remove extraneous comma from 1
foo

.
. display "Sometimes it does not"
Sometimes it does not

.
. test1 bar
bar
bar
Remove extraneous comma from varlist
bar
bar
Remove extraneous comma from 1
bar

.
end of do-file

.

If I define the option as required (rather than optional as above), --test1 foo, option(1 1 1)-- still produces what I think of as a bug.

Is the bug in --syntax--, or is the bug in my understanding of syntax?

Thanks!

Michael Manti
[email protected]



*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/


*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index