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!
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.