I am trying to find any row that contains a number from 2-9 in it in proc sql. I have tried multiple solutions and have researched other peoples questions on this topic and nothing seems to produce a result for me. Here is what I have tried:
proc sql;
select *
from one
where Make like '%[2-9]%';
run;
proc sql;
select *
from one
where Make like '[2-9]';
run;
proc sql;
select *
from one
where Make like '.[2-9].';
run;
proc sql;
select *
from one
where Make contains '[2-9]';
run;
proc sql;
select *
from one
where Make like '.*[2-9]*.';
run;
None of these seem to produce any results for me. Thank you in advance for any help.
Show test data, in the form of a datastep. As such I can only guess, but maybe think about it differently or:
where 2 <= make <= 9;
Try this:
where findc(make,'23456789');
This WHERE condition is met if the value of (character) variable MAKE contains at least one of the digits 2, 3, ..., 9.
(And don't forget that PROC SQL steps end with a QUIT statement, not RUN.)
You might show a few explicit values of the variable MAKe, indicate if the variable is character or numeric, and show which ones of your examples you want to treat as 'in range' (and include some examples that are not in range)
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.