Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Wildcards

Status
Not open for further replies.

dblan

MIS
Jul 6, 2007
58
US
Is there a way to write a where statement to look at only certain positions in the text of a field? Maybe a example would be best.
Something like this works:
Code:
data want;
set have;
where (phone = '5555555555' or substr(phone,4,3) = '555');
run;

The results are phone numbers that are all 5's plus the ones where the middle 3 are 5's are returned.

But I'd like to find a cleaner way. Is there a way to say something like this?
Code:
data want;
set have;
where (phone in ('5555555555','***555****');
run;
 
For the example you have given I don't understand the need to specify '555555555' and not just this.
Code:
where substr(phone,4,3) = '555';
If you wanted to use wildcards in the SAS where clause
Code:
where phone like '___555____';
You can also do this in SQL, just replace underscores with percentages. For more complex patterns you could turn to prx
Code:
if prxmatch(prxparse('/\d{3}5{3}\d{4}/'),phone);

I'm not aware of being able to use wildcards with "in", but hopefully prx should suffice.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top