BookmarkSubscribeRSS Feed
1239
Calcite | Level 5

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;
3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

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;
1239
Calcite | Level 5

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.

PeterClemmensen
Tourmaline | Level 20

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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 912 views
  • 0 likes
  • 2 in conversation