[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
Re: st: if command
At 03:26 PM 2/12/2004 -0500, Danielle Ferry wrote:
Can anyone please explain when the if command requires quotes around the
expression and when it does not?
As far as I know, if you are comparing to a string constant, you need quotes.
For example, I've found the following seemingly quirky behavior:
1) if "`1'"=="aRate" | "`1'"=="bRate" | "`1'"=="pRate" --> requires quotes
2) if `1'==aRate --> does not require quotes
3) if "`1'"=="apRatio" --> requires quotes
Example 2 probably ought to have quotes if it is meant to test a string
value. It would, however, pass as a legitimate expression if...
aRate happens to be a variable name and...
it is numeric and so is `1' (that is the contents of the local 1), or
it is string, and `1' contains enclosing quotes (I haven't tried this), or
it is either numeric or string, and `i' is also a variable name of a
But in these cases, you are implicitly testing observation 1, which you
might not have intended.
Example 2 would also pass if aRate is a scalar and `1' is numeric (and if
`1' is a variable name, then you are testing observation 1).
In any case, while Example 2 might sometimes pass, it is probably not doing
what you intended.
I hope this helps.
Institute for Policy Studies
Johns Hopkins University
* For searches and help try: