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

Hi,

 

By way of example, I have two groups of strings as shown below, a1-a3 and b1-b3.

 

I want to know if at least one of the strings in a1-a3 is equal to at least one of the strings in b1-b3. Then flag the rows which satisfy this.

 

I imagine this will be done using arrays and a do loop. I realise my attempt in the code below will only work if all a1-a3 are identical to b1-b3.

 

I would really appreciate some help here.

 

Thanks a lot

 

Matt

 

data table ;
input a1 $ a2 $ a3 $ b1 $ b2 $ b3 $ match $ ;
cards ;
a b c a b c Yes
a b c a d e Yes 
a b c d e f no 
a b c a b e Yes
; 
run ;

data table ;
set table ;
array check1 a1-a3 ;
array check2 b1-b3 ;
do i=1 to 3 ;
if check1(i)=check2(i) then match =1 ;
else match=0 ;
end ;
run ;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Something like:

data table ;
  input a1 $ a2 $ a3 $ b1 $ b2 $ b3 $;
cards ;
a b c a b c
a b c a d e
a b c d e f 
a b c a b e
; 
run;

data want;
  set table;
  array a{3};
  do i=1 to dim(a);
    if whichc(a{i},of b:) then match="yes";
  end;
run;

 

 

 

View solution in original post

3 REPLIES 3
Kurt_Bremser
Super User

Just a little change in the logic:

data table;
set table;
array check1 a1-a3;
array check2 b1-b3;
match = 0;
do i = 1 to 3;
  if check1{i} = check2{i} then match = 1;
end;
run;
mattteale
Fluorite | Level 6

Thank you so much pal

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Something like:

data table ;
  input a1 $ a2 $ a3 $ b1 $ b2 $ b3 $;
cards ;
a b c a b c
a b c a d e
a b c d e f 
a b c a b e
; 
run;

data want;
  set table;
  array a{3};
  do i=1 to dim(a);
    if whichc(a{i},of b:) then match="yes";
  end;
run;

 

 

 

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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
  • 3 replies
  • 1562 views
  • 2 likes
  • 3 in conversation