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