Reputation: 189
I'm having some unexpected errors in achieving the following functionality. In this example code, I have the temperature on several days of the week. For this generalized example, I'm interested in determining the days that are 72,74, or 65 degrees. As an output, a variable should be created that contains the day of the week that is within this temperature range. Also, please note that in these data there is only ever 1 day that would fall within have one of these temperatures.
Monday Tuesday Wednesday Day of Interest
72 78 80
61 78 74
Monday Tuesday Wednesday Day of Interest
72 78 80 2
61 78 74 4
I wrote the following code, with the generous help of the great folks here at StackOverflow,
IF (Monday = 65 OR 72 OR 74) Day_Of_Interest = 2.
IF (Tuesday= 65 OR 72 OR 74) Day_Of_Interest = 3.
IF (Wednesday = 65 OR '72' OR 74) Day_Of_Interest = 4.
IF (Thursday = 65 OR 72 OR 74) Day_Of_Interest = 5.
but sadly it returns an error:
IF A relational operator may have two numeric operands or two character
string operands. To compare a character string to a numeric quantity,
consider using the STRING or NUMBER function.'
I tried changing the code to be akin to '65' OR '72', but this produced another error. I would really appreciate if anyone had any thoughts on how to make this work. I know the example above isn't the best, but it's the best I could think of. If you need anymore details I'd be more than happy to oblige. Thanks so much for your help!
Edit: I should say that this code does work if I am just looking for one number, say 72.
Upvotes: 3
Views: 2587
Reputation: 11310
Using IF
with multiple comparisons will only work this way:
IF (Monday = 65 OR Monday = 72 OR Monday = 74) Day_Of_Interest = 2.
But in this situation ANY
function will be more useful:
IF any(Monday, 65, 72, 74) Day_Of_Interest = 2.
Now if you want to do this for all weekdays, you can use a loop:
do repeat day=Sunday Monday Tuesday Wednesday Thursday Friday Saturday
/Dnum=1 2 3 4 5 6 7.
IF any(day, 65, 72, 74) Day_Of_Interest = Dnum.
end repeat.
exe.
Upvotes: 2