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?
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.
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
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.
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!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.