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
NAME | YEAR | Char1 | Char2 |
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 |
desired result
NAME | YEAR | Including |
JOY | 2011 | 1 |
JOY | 2011 | 1 |
JOY | 2012 | 1 |
JOY | 2012 | 1 |
JOY | 2012 | 1 |
JOY | 2013 | 1 |
JOY | 2013 | 0 |
If you know how, please help me.
The INDEXW function may be what you are looking for:
data want;
set have;
including=(indexw(char2,char1,', ')>0);
run;
The INDEXW function may be what you are looking for:
data want;
set have;
including=(indexw(char2,char1,', ')>0);
run;
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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: