BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi I have a data set

input string1 $char60. string2 $char60.
datalines;
string1=Lycanthrope
string2=Luz vagaT
output=no match
string1=When Your Heart Stops Beating
string2=When your heart stops beating
output=match
string1=155 44 string2=155 (+44)
output=match
string1=Come Mai 883
string2=Come Mai (OcraMiX_ dj) - 883
output=match

I would like SAS to output if string1 has two or more words which match with string 2 a MATCH and if there are no words matching then it should display NO MATCH.

I've tried the complev, compged, SPEDIS functions and none of these seem to be able to return the desired result. Message was edited by: celendin
2 REPLIES 2
Patrick
Opal | Level 21
Hi

I wouldn't know of a SAS function doing this for you - but you could code it.

Something like the code below could do:

data have;
length string1 string2 $60.;
string1='Lycanthrope';
string2='Luz vagaT ';
output;
string1='Come 883 Mai';
string2='Come (OcraMiX_ dj) Mai';
output;
run;

data want;
set have;
length SubString1 $60.;

i=1;
counter=0;
SubString1=scan(String1,i,' ');

do while(SubString1 ne '');
counter + find(String2,strip(SubString1))>0;
if counter=2 then leave;
i+1;
SubString1=scan(String1,i,' ');
end;
run;

proc format;
value counter
2='Match'
other='No Match'
;
run;

proc print data=want;
format counter counter.;
var counter String1 String2;
run;

You didn't tell us whether the sequence of words is relevant or not.

If it is relevant then some additional logic would be necessary (i.e. you could define in the find function to only search the string beginning from a certain position - later than where you had already a hit).

HTH
Patrick
deleted_user
Not applicable
thanks Patrick that's exactly what i needed... thank you so much

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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