data ds;
input text $;
datalines;
abcll12
slff37
uyxiiz3
123
;
run;
proc sql;
select * from ds
where text like '%[a-z]%' as alphabet and like '%[0-9]%' as numeric ;
quit;
I want to get alphabet and numeric from this data instead of compress function using like operator
Your code does not make any sense. Please show us the expected result from your example data.
Please show the expected result, it is not clear what you want. And please explain why you don't want to use compress.
Alphabet | Numeric |
abcll | 12 |
slff | 37 |
uyxiiz | 3 |
123 | 123 |
So you want to create two new variables, one containing only numeric characters, the other the rest?
The proper tool for this is the COMPRESS function, as you already mentioned, so use it (Maxim 14).
The WHERE clause in SQL is for filtering observations, not for creating variables.
PS why do you have the digits "123" in alphabet in the last observation? There, the variable should be empty.
And what do you expect if the original value is "a1b2c3"? Or is it 100% sure that you have one block of non-digits and another of only digits?
Also see Maxim 1: Read the Documentation:
The LIKE operator does not support regular expressions.
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.