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 2025: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 2026 views
  • 1 like
  • 3 in conversation