07-06-2014 01:55 PM
I would like to learn how to calculate % change, when two strings are compared.
Here is the original file:
As there is only one character that is different in the first observation, it should return 1/3 %(number of deviation / total number of char in the original).
Desired output is something like this:
Thanks in advance,
07-06-2014 02:51 PM
Try this for the desired output.
input obs var1 $ var2 $;
1 RAT CAT
2 BELL BALL
3 TIME TOM
do i=1 by 1 while(substr(var1,i,1) ne ' ');
if index(var2,substr(var1,i,1))>0 then cnt+1;
data final (drop=i cnt);
format diff 8.0;
07-06-2014 03:24 PM
Approximate matches between strings is an already well researched topic. SAS provides you with many tools in that area. Please look at SAS functions COMPGED, COMPLEV, SOUNDEX, and SPEDIS.