Easy One.... Where string starts with [A-Z].....

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 10
Accepted Solution

Easy One.... Where string starts with [A-Z].....

Hi all.

Hopefully an easy one for you!

In T-SQL i used to write something along the lines of

Select *

from Table1

Where field1 like '[A-Z]%'

That would select all records from Table1 where field1 started with any character between A and Z. It would not bring back records starting with a number or a non alphanumeric.

If i did

...

Where field1 like '[A-Z][0-9]%' it would return al rows starting with one letter and then a number.. like "S2 Antfarm"

How can i do this in SAS?


Accepted Solutions
Solution
‎01-24-2013 09:30 AM
Super Contributor
Posts: 543

Re: Easy One.... Where string starts with [A-Z].....

Posted in reply to ChrisElias

Hi.

I believe PRXMATCH would allow you to "match" any alphanumeric

Something like this:

data want;

     set have(where = ( (prxmatch("m/[a-z]|[0-9]/i",your_variable) > 0)) );

run;

For example,

using sashelp.class if you want to keep the records that contain the letter 'b' or any number in the name:

data want;

     set sashelp.class(where = ( (prxmatch("m/|[0-9]/i",name) > 0) ));

run;

Good luck,

Anca.

View solution in original post


All Replies
Trusted Advisor
Posts: 1,137

Re: Easy One.... Where string starts with [A-Z].....

Posted in reply to ChrisElias

Hi Chris,

We have function in sas such as anyalnum,anyalpha(),anydigit()

anyalnum(), in a string if there is any alpha numeric value it will give the position of that character in numbers, if none is found then it results in 0, similary

anyalpha(), in a string it searches for only character value

anydigit(), in a string it searches for only numeric value

Thanks,

Jagadish

Thanks,
Jag
Solution
‎01-24-2013 09:30 AM
Super Contributor
Posts: 543

Re: Easy One.... Where string starts with [A-Z].....

Posted in reply to ChrisElias

Hi.

I believe PRXMATCH would allow you to "match" any alphanumeric

Something like this:

data want;

     set have(where = ( (prxmatch("m/[a-z]|[0-9]/i",your_variable) > 0)) );

run;

For example,

using sashelp.class if you want to keep the records that contain the letter 'b' or any number in the name:

data want;

     set sashelp.class(where = ( (prxmatch("m/|[0-9]/i",name) > 0) ));

run;

Good luck,

Anca.

Occasional Contributor
Posts: 10

Re: Easy One.... Where string starts with [A-Z].....

Posted in reply to AncaTilea

Thanks once again Jagadish for a quick response.

Anca - you were right on the button with that one!! Excellent and thanks for you help - you're a genius!

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 489 views
  • 1 like
  • 3 in conversation