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)

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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!

Register now

Develop Code with SAS Studio

Get started using SAS Studio to write, run and debug your SAS programs.

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
  • 1262 views
  • 0 likes
  • 4 in conversation