Thursday, October 31, 2019

Is it possible to not set values of optional integer arguments with the syntax command

When specifying optional arguments integer arguments using the syntax command it is usually necessary to set a value. Is it possible to get round this feature?

For example I am writing a program where an argument is optional as long as option1 hasn't also been given. If option1 has been given I want the program to produce an error if the argument has not been given.

A work around is to set the value to one that would be implausible for the user to enter but this does not seem ideal. Is there a better way to do this?

Code:
prog define foo
    syntax, [option1, a_number(integer -99999)]
    if `a_number' == -99999 & "`option1'" != "" {
        di as error "a_number must be provided if option1 is specified"
    }
end

No comments:

Post a Comment