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?

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