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;
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!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.