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

Hello,

 

I want to determine whether one character variable(Char1) is included in another character variable(Char2).

 

The data and the desired results are as follows:

 

data

 

NAMEYEARChar1Char2
JOY2011AAAA, BB
JOY2011BBAA, BB
JOY2012AAAA, BB, CC
JOY2012BBAA, BB, CC
JOY2012CCAA, BB, CC
JOY2013CCCC
JOY2013BBCC

 

desired result

 

NAMEYEARIncluding
JOY20111
JOY20111
JOY20121
JOY20121
JOY20121
JOY20131
JOY20130

 

If you know how, please help me.

1 ACCEPTED SOLUTION

Accepted Solutions
s_lassen
Meteorite | Level 14

The INDEXW function may be what you are looking for:

data want;
  set have;
  including=(indexw(char2,char1,', ')>0);
run;

View solution in original post

2 REPLIES 2
s_lassen
Meteorite | Level 14

The INDEXW function may be what you are looking for:

data want;
  set have;
  including=(indexw(char2,char1,', ')>0);
run;
PeterClemmensen
Tourmaline | Level 20
data have;
input NAME $ YEAR Char1 $ Char2 $ 13-22;
datalines;
JOY 2011 AA AA, BB
JOY 2011 BB AA, BB
JOY 2012 AA AA, BB, CC
JOY 2012 BB AA, BB, CC
JOY 2012 CC AA, BB, CC
JOY 2013 CC CC
JOY 2013 BB CC
;

data want;
    set have;
    Including=find(Char2, Char1, 't')>0;
run;

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