Here is another way to approach it, building on earlier suggestions.
numlist "`1' `2' `3' `4' `5'", int min(4) max(4)
args a b c d
If 3 or fewer arguments are specified, the test will fail.
If 5 or more arguments were specified, "`5'" will be non-empty and the
test will fail. But you must mention `5' for it to test.
Or you could just use `0'.
numlist "`0'", int min(4) max(4)
With this, we need not name the arguments until we know we have the
right number.
If the logic is right, then the differences are mostly of taste,
except that simplicity and clarity should appeal universally.
Details differ if there are other elements to the syntax, such as options.
A program that takes on only numerical arguments might qualify as an
"immediate" command. Start with -help immediate- for suggestions. It's
a good convention that immediate command names end with "i", although
the converse need not be true.
Nick
On Fri, Mar 22, 2013 at 8:47 AM, John Antonakis <John.Antonakis@unil.ch> wrote:

---------- Forwarded message ----------
From: Nick Cox <njcoxstata@gmail.com>
Date: Fri, Mar 22, 2013 at 8:30 AM
Subject: Re: st: -args- how to flag when missing or too many arguments
To: statalist@hsphsun2.harvard.edu
John: You should know that the Statalist FAQ advises against "does not
work" as an error report.
if "`chi'" == ""
is sufficient as a test of there not being four arguments. Whether
there are none, one, two, or three, it follows in each case that there
was no fourth argument.
Your code does not test that the arguments are integers (which you can
do in one line with -numlist-).
Nick
On Fri, Mar 22, 2013 at 7:51 AM, John Antonakis <John.Antonakis@unil.ch>
wrote:

Thanks, Austin.
This works too, except for when w > 4; it does not display the error.
The
program just ignores any arguments beyond 4 arguments (as is the
default
in
Stata).
Best,
J.
__________________________________________
John Antonakis
Professor of Organizational Behavior
Director, Ph.D. Program in Management
Faculty of Business and Economics
University of Lausanne
Internef #618
CH-1015 Lausanne-Dorigny
Switzerland
Tel ++41 (0)21 692-3438
Fax ++41 (0)21 692-3305
http://www.hec.unil.ch/people/jantonakis
Associate Editor
The Leadership Quarterly
__________________________________________
On 21.03.2013 22:54, Austin Nichols wrote:

John,
I think I would address this with something like this
cap pr drop john
pr john
vers 12.1
args a b c d
if !inrange(`: word count `0'', 1, 4) {
di as err "Please enter data after " ///
"the command john as follows: vars df N chi"
e 198
}
numlist "`0'" ,int r(>0)
end
Best
Daniel
--
Hi:
I am writing a program and would like Stata to return an error if an
argument is missing or there are too many of them.
For example, if an argument is not an integer, the below will return
an
error:
program define john, rclass
version 12
args no_vars df N chi
if `no_vars'<0 | `df'<0 | `N'<0 | `chi'<0 {
di in red "You have to use integers."
exit 498
}
end
Now, how do I make Stata display:
di in red "Please enter data after the command john as follows: vars
df
N
chi"
.....in cases where (a) there is a missing value (i.e., the user
missed putting 4 numbers) and (b) if the user provides too many
numbers (i.e., 5 instead of 4).