Statalist The Stata Listserver


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

st: one-variable varlist with options includes extraneous comma


From   Michael Manti <mmanti@mac.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: one-variable varlist with options includes extraneous comma
Date   Tue, 25 Jul 2006 07:19:43 -0400

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
mmanti@mac.com



*
* 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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index