BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ChrisElias
Calcite | Level 5

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?

1 ACCEPTED SOLUTION

Accepted Solutions
AncaTilea
Pyrite | Level 9

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

3 REPLIES 3
Jagadishkatam
Amethyst | Level 16

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
AncaTilea
Pyrite | Level 9

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.

ChrisElias
Calcite | Level 5

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!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 6020 views
  • 1 like
  • 3 in conversation