BookmarkSubscribeRSS Feed
alilacey0
Fluorite | Level 6

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.

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;

 

FreelanceReinh
Jade | Level 19

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.)

ballardw
Super User

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)

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

SAS Enterprise Guide vs. SAS Studio

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1200 views
  • 0 likes
  • 4 in conversation