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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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