BookmarkSubscribeRSS Feed
cool1993
Fluorite | Level 6

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:

ObsCHAR1CHAR2
1A001940, A007280.
2A001940, A007280.
3A001940, A007280A001940, A007280
4A001940A001940, A007280
5A001940, A007280A001940
6A001940, A007280A001940
7A001940, A007280A001940, A007280
8A001940, A007280A001940, A007280
9A001940, A007280, A104700A001940, A007280
10A001940, A007280, A104700A001940, A007280
11A001940, A007280, A104700A001940, A007280
12A001940, A007280, A012160, A104700A001940, A007280, A104700
13A001940, A007280, A012160, A104700A001940, A007280, A104700
14A001940, A007280, A012160, A104700A001940, A007280, A012160, A104700
15A001940, A007280, A012160, A104700A001940, A007280, A012160, A104700
16A001940, A012160, A104700A001940, A007280, A012160, A104700
17A001940, A012160, A104700A001940, A007280, A012160, A104700

 


Desired result:

ObsCHAR1CHAR2want
1A001940, A007280.0
2A001940, A007280.0
3A001940, A007280A001940, A0072801
4A001940A001940, A0072800
5A001940, A007280A0019401
6A001940, A007280A0019401
7A001940, A007280A001940, A0072801
8A001940, A007280A001940, A0072801
9A001940, A007280, A104700A001940, A0072801
10A001940, A007280, A104700A001940, A0072801
11A001940, A007280, A104700A001940, A0072801
12A001940, A007280, A012160, A104700A001940, A007280, A1047001
13A001940, A007280, A012160, A104700A001940, A007280, A1047001
14A001940, A007280, A012160, A104700A001940, A007280, A012160, A1047001
15A001940, A007280, A012160, A104700A001940, A007280, A012160, A1047001
16A001940, A012160, A104700A001940, A007280, A012160, A1047000
17A001940, A012160, A104700A001940, A007280, A012160, A1047000



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.

1 REPLY 1
Astounding
PROC Star

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;

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
  • 1 reply
  • 270 views
  • 0 likes
  • 2 in conversation