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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

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