BookmarkSubscribeRSS Feed
glz
Fluorite | Level 6 glz
Fluorite | Level 6

Hello all,

I have an example data:

The column in data A includes special characters: AA*B, A**B, AB**, and here * can be anything, both letter and number. 

The column in data B without special character: AADB, ABBF, AB3D.

so in this example, since AADB satisfies AA*B, AB3D satisfies AB**, they will be reported.

I do not know how to deal with them in SAS, could anyone help me to figure this out?

Thanks a lot. 

 

1 REPLY 1
Tom
Super User Tom
Super User

Sounds a lot like what the LIKE operator can handle.

You can use LIKE in SQL queries.

 

If the text literally has * to represent a single character you will want to convert those to _ which is what the LIKE operator uses to match a single character.

 

proc sql;
  create table want as 
  select a.*,b.xxx
  from table1 A 
    left join table2 B
   on a.column like translate(b.column,'_','*')
  ;
quit;

If the values in the pattern can include actual _ characters you will need to first prefix those with an escape character.

   on a.column like translate(tranwrd(b.column,'_','^_),'_','*') escape '^'

If you cannot find an escape character to use that cannot appear in the pattern string then you will need to escape those also.

   on a.column like translate(tranwrd(tranwrd(b.column,'^','^^'),'_','^_),'_','*') escape '^'

 

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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
  • 1 reply
  • 572 views
  • 1 like
  • 2 in conversation