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;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 428 views
  • 3 likes
  • 3 in conversation