BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Kalai2008
Pyrite | Level 9

Hello,

 

I need a help matching columns. Column A and B has names, I want to match names in Column B. If column B name matches with Column A (any order or any part is fine from Col A), need to create a flag with Y or N. Column B name must match exactly with Column A . I tried with SCAN function and few other functions. Proc sql also will work for me. Column A has 1- 6  names. Column B has 1-4 names.

 

Data Have

 

Column A                                                             Column B

CAMACHO ANAYA FAIBER                                ANAYA

EVER ANDRES NAVARRO Navas  MELO        Navarro Navas                       

EVER ANDRES NAVARRO MELO                     Navarro Navas    

PINILLA AGUDELO JOVANNY                           PINIL

PINILLA AGUDELO JOVANNY                           PINILLA

 

 

Data Want

 

Column A                                                          Column B                                Flag

CAMACHO ANAYA FAIBER                               ANAYA                                   Y

EVER ANDRES NAVARRO Navas  MELO        Navarro Navas                       Y

EVER ANDRES NAVARRO MELO                     Navarro Navas                       N

PINILLA AGUDELO JOVANNY                           PINIL                                     N

PINILLA AGUDELO JOVANNY                           PINILLA                                 Y

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
data have;
input Column_A $40.       Column_B $20.;
cards;
CAMACHO ANAYA FAIBER                                ANAYA
EVER ANDRES NAVARRO Navas  MELO             Navarro Navas                       
EVER ANDRES NAVARRO MELO                     Navarro Navas    
PINILLA AGUDELO JOVANNY                           PINIL
PINILLA AGUDELO JOVANNY                           PINILLA
;

data want;
 set have;
 flag=ifc(findw(column_a, strip(column_b), ' ', 'i'),'Y','N');
run;

 Hi @Kalai2008  This is a pretty good question where FINDW in my opinion best fits the solution. You need a case insensitive search though that is taken care by 'i'

View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20
data have;
input Column_A $40.       Column_B $20.;
cards;
CAMACHO ANAYA FAIBER                                ANAYA
EVER ANDRES NAVARRO Navas  MELO             Navarro Navas                       
EVER ANDRES NAVARRO MELO                     Navarro Navas    
PINILLA AGUDELO JOVANNY                           PINIL
PINILLA AGUDELO JOVANNY                           PINILLA
;

data want;
 set have;
 flag=ifc(findw(column_a, strip(column_b), ' ', 'i'),'Y','N');
run;

 Hi @Kalai2008  This is a pretty good question where FINDW in my opinion best fits the solution. You need a case insensitive search though that is taken care by 'i'

Kalai2008
Pyrite | Level 9
Awesome! Thank you so much. It worked. I never explored FINDW function.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 2 replies
  • 1322 views
  • 0 likes
  • 2 in conversation