Building models with SAS Enterprise Miner, SAS Factory Miner, SAS Visual Data Mining and Machine Learning or just with programming

SAS compare if two strings have two or more words same

Reply
N/A
Posts: 0

SAS compare if two strings have two or more words same

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
SAS Employee
Posts: 32

Re: SAS compare if two strings have two or more words same

Posted in reply to deleted_user
I think you would need to use the scan function in a do loop for string1 to parse into individual terms, then you could use substr for each term to see if it occurs in string2. It would probably be more accurate (only match complete words) to use scan on both string1 and string2. In that case you should use a data structure like an array or hash to save the terms from string1 and then look them up for a match when your scanning string2.

Russ
Ask a Question
Discussion stats
  • 1 reply
  • 199 views
  • 0 likes
  • 2 in conversation