I am trying to create a variable that is a 1 if it is in a range
My code looks like this:
data new;
set old;
if var1 in (41000:41099) then var2 = 1;
else var2 = 0;
run;
It turns up with only 0's.
When I run this
proc freq data = new;
table var1;
where var1 in (41000:41099);
run;
It shows 50 numbers and hundreds of numbers in the freq. What am I doing wrong?
Why write it that way in the first place?
data new;
set old;
var2=0;
if 41000 <= var1 <= 41099) then var2=1;
run;
allow SAS to do the evaluation; the results are boolean, i.e. (0,1);
var2 = (41000 <= var1 <= 41099);
VAR1 must be an integer for IN(41000:41099) specification to match;

41000 <= var1 <= 41099
I think the problem you are experiencing is not in the code you are writing, which works just fine, but perhaps in the dataset you are reading in.
My hunch is that the user data _null_ could be right: make sure var1 in your dataset is actually a numeric variable.
Otherwise if you still have trouble, I'd suggest giving us a sample of the dataset you are reading in.
What is actually happening is further revealed in the SAS log when IN is used in a WHERE statement.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.