[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: RE: invalid -syntax- when moving the option-bracket
> I am writing a program with several options and I am
> apparently missing something obvious in writing the -syntax-.
> The sytnax looks like:
> syntax [varlist(num)] , opt1(varname) opt2(int) opt3(int) ///
> opt4(int) [ opt5(varname) otheropt SAVing(str) REPLACE ]
> This program works.
> However, if I move the options-bracket -[- forward, Stata
> immediately gives me an -invalid syntax-error when I run the
> program without executing one line of code (at least -set
> trace on- doesn't show any executed code). E.g., the following
> does not work (-[- moved forward, now between opt1 and opt2):
> syntax [varlist(num)] , opt1(varname) [ opt2(int) opt3(int) ///
> opt4(int) opt5(varname) otheropt SAVing(str) REPLACE ]
> Where could my mistake be hidden?
Now that, for example,
is a genuinely optional option Stata expects you to specify
a default. For example, specify a 0 default.
One common trick is to specify a sensible default.
An alternative is to specify
and then later check whether "`opt2'" != "". If it is, the user
specified something: what's more, it must be legal, otherwise
the input would have been rejected. That's attractive because you can
constraints as in
opt2(numlist int >0)
which with the other route you have to spell out at some length.
* For searches and help try: