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.

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
  • 3 replies
  • 395 views
  • 0 likes
  • 2 in conversation