It is a good idea to paste your code by copy from your editor and paste into a text box opened on the forum using the </> icon above the message window. The forum software will reformat text when pasted into the main message window and may hide the actual problem because of the conversion.
From ancient behaviors with some keyboards I don't trust >= and =< and use the SAS GE and LE comparisons in code. Sometimes a >= or <= may just happen to be a single character in an extended character set that SAS won't use for comparisons.
It is also a good idea to provide data in the form of a working data step as when I create data set such as with this data step:
data have;
input var1 $ var2 $;
datalines;
ROOMA DESK01A
ROOMA DESK01B
ROOMA DESK05B
ROOMA DESK06A
ROOMB DESK09A
ROOMB DESK09B
ROOMC DESK01B
ROOMC DESK05A
ROOMD DESK10B
ROOME DESK15A
ROOME DESK15B
ROOME DESK16
;
And get this log for YOUR code:
101 %let range_1 = 13;
102 %let range_2 = 24;
103 data test;
104 set have;
105 if input(compress(var2,'', 'A'), 8.) >= &range_1. and
105! input(compress(var2,'', 'A'), 8.) <= &range_2. then test = 'YEAH';
106 run;
NOTE: There were 12 observations read from the data set WORK.HAVE.
NOTE: The data set WORK.TEST has 12 observations and 3 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
which has no error. So one suspects something in your data may be involved.
Resulting data set:
var1
var2
test
ROOMA
DESK01A
ROOMA
DESK01B
ROOMA
DESK05B
ROOMA
DESK06A
ROOMB
DESK09A
ROOMB
DESK09B
ROOMC
DESK01B
ROOMC
DESK05A
ROOMD
DESK10B
ROOME
DESK15A
YEAH
ROOME
DESK15B
YEAH
ROOME
DESK16
YEAH
The variables Var1 and Var2 are length 8. If your variables white space values like leading spaces, tabs or NULL characters (ASCII 255) then we can't see those and may be reformatted by the forum software to blanks.
I would try using : compress(var2,'', 'dk') to keep only digits. This would protect against non-displayed characters like Null.
With those thoughts in mind, when I create a data set with this code:
data have;
input var1 $ var2 $;
datalines;
ROOMA DESK01A
ROOMA DESK01B
ROOMA DESK05B
ROOMA DESK06A
ROOMB DESK09A
ROOMB DESK09B
ROOMC DESK01B
ROOMC DESK05A
ROOMD DESK10B
ROOME DESK15A
ROOME DESK15B
ROOME DESK16
;
Also any error message should be copied from the log with the code of the procedure or data step that generates the error along with the error and all other notes or warnings for that step. Copy the text from the log, open a text box using the </> and paste. Many of those errors will have diagnostics that indicate where the error is found.
As an aside, I strongly recommend using numeric results in stead of 'Yes' or similar for comparisons especially if the result is binary Yes/No, True/False, Present/Not present or similar.
You could use
Test = value1 LE TestValue LE value;
Test would have value 1 when true and 0 when false. It is often much easier to get reportable values from the numeric values a Sum of Test would have the count of true values, mean would be the percentage true values as as decimal. Questions like all true, all false, more true than false are also often easier to determine using sum of the variable compared to count of values, N statistic, in proc summary, means, report or tabulate than dealing with character values.
... View more