Hello,
I want to determine whether CHAR2 variable is included in CHAR1 variable.
If CHAR2's inputs are all included in CHAR1, then want variable has a value of 1. Otherwise, it has a value of 0.
The data and the desired results are as follows:
Data:
Obs | CHAR1 | CHAR2 |
1 | A001940, A007280 | . |
2 | A001940, A007280 | . |
3 | A001940, A007280 | A001940, A007280 |
4 | A001940 | A001940, A007280 |
5 | A001940, A007280 | A001940 |
6 | A001940, A007280 | A001940 |
7 | A001940, A007280 | A001940, A007280 |
8 | A001940, A007280 | A001940, A007280 |
9 | A001940, A007280, A104700 | A001940, A007280 |
10 | A001940, A007280, A104700 | A001940, A007280 |
11 | A001940, A007280, A104700 | A001940, A007280 |
12 | A001940, A007280, A012160, A104700 | A001940, A007280, A104700 |
13 | A001940, A007280, A012160, A104700 | A001940, A007280, A104700 |
14 | A001940, A007280, A012160, A104700 | A001940, A007280, A012160, A104700 |
15 | A001940, A007280, A012160, A104700 | A001940, A007280, A012160, A104700 |
16 | A001940, A012160, A104700 | A001940, A007280, A012160, A104700 |
17 | A001940, A012160, A104700 | A001940, A007280, A012160, A104700 |
Desired result:
Obs | CHAR1 | CHAR2 | want |
1 | A001940, A007280 | . | 0 |
2 | A001940, A007280 | . | 0 |
3 | A001940, A007280 | A001940, A007280 | 1 |
4 | A001940 | A001940, A007280 | 0 |
5 | A001940, A007280 | A001940 | 1 |
6 | A001940, A007280 | A001940 | 1 |
7 | A001940, A007280 | A001940, A007280 | 1 |
8 | A001940, A007280 | A001940, A007280 | 1 |
9 | A001940, A007280, A104700 | A001940, A007280 | 1 |
10 | A001940, A007280, A104700 | A001940, A007280 | 1 |
11 | A001940, A007280, A104700 | A001940, A007280 | 1 |
12 | A001940, A007280, A012160, A104700 | A001940, A007280, A104700 | 1 |
13 | A001940, A007280, A012160, A104700 | A001940, A007280, A104700 | 1 |
14 | A001940, A007280, A012160, A104700 | A001940, A007280, A012160, A104700 | 1 |
15 | A001940, A007280, A012160, A104700 | A001940, A007280, A012160, A104700 | 1 |
16 | A001940, A012160, A104700 | A001940, A007280, A012160, A104700 | 0 |
17 | A001940, A012160, A104700 | A001940, A007280, A012160, A104700 | 0 |
I tried the following solution, but it doesn't apply because the order of input is different.
Want = (indexw(CHAR1,CHAR2,', ')>0);
If you know the solution, please help me.
You will need to examine each word within CHAR2 separately. For example:
want=0;
if char2=' ' then want=1;
else do k=1 to countw(char2, ',' ) until (want=1) ;
if index(char1, scan(char2, k) ) = 0 then want=1;
end;
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.