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)
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.