BookmarkSubscribeRSS Feed
BrahmanandaRao
Lapis Lazuli | Level 10
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

7 REPLIES 7
andreas_lds
Jade | Level 19

Please show the expected result, it is not clear what you want. And please explain why you don't want to use compress.

BrahmanandaRao
Lapis Lazuli | Level 10
Alphabet Numeric
abcll 12
slff 37
uyxiiz 3
123 123
Kurt_Bremser
Super User

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.

andreas_lds
Jade | Level 19

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?

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

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