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 '^'

 

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