Hi,
I am trying to find the values when Name1 contains Name2 values then it should output however I am not able to find out either with FIND or INDEX functions. Please help in getting the output. I want all the records as matching except last record.
data test1;
input Name1 $12. Name2 $25.;
datalines;
ORANGE APPLE APPLE
OATS WHEAT WHEAT
WHEAT GRAIN GRAIN
WHEATGRAIN WHEAT-GRAIN
WHEAT-GRAIN WHEAT
APPLE ORANGE ORANGE
WEAT ORANGE GRAIN
;
run;
Given the lengths of your strings, I'm guessing your problem is caused by trailing blanks. Try this
data test1;
input Name1 $12. Name2 $25.;
datalines;
ORANGE APPLE APPLE
OATS WHEAT WHEAT
WHEAT GRAIN GRAIN
WHEATGRAIN WHEAT-GRAIN
WHEAT-GRAIN WHEAT
APPLE ORANGE ORANGE
WEAT ORANGE GRAIN
;
run;
data want;
set test1;
if index(Name1, trim(Name2));
run;
Thanks for the code however Row # 4 WHEATGRAIN WHEAT-GRAIN didn't pull from your code. Only last row shouldn't be pulled but rest of the rows should be pulled.
What is the logic here? You can remove anything but digits and numbers from the name2 strings and do the match, but I do not know if that is correct in your case? Please be specific.
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 25. 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.