BookmarkSubscribeRSS Feed
Ksharp
Super User

If you are trying to make some EDIT DISTANCE for two string, then PG 's suggest is good, SAS has already built-in some function for that purpose.

Otherwise , try

data have;
input obs var1 $ var2 $;
datalines;
1 RAT CAT
2 BELL BALL
3 TIME TOM
;
run;
data want(drop=n i);
 set have;
 n=0;
 do i=1 to length(var1);
  if char(var1,i) ne char(var2,i) then n+1;
 end;
 dif=divide(n,length(var1));
run;

Xia Keshan

3 REPLIES 3
JAR
Obsidian | Level 7 JAR
Obsidian | Level 7

Thank you so much!

JAR
Obsidian | Level 7 JAR
Obsidian | Level 7

HI KSharp,

How will I use the same logic for two different string, where words (unlike character here) have pattern:

Here is an example:

String 1: "It is a cat"

String 2: "This is a cat"

Can I use SAS to calculate that "String2 is 25% different from String1"?

Jijil Ramakrishnan

Ksharp
Super User

OK. No problem.

data have;
input obs var1 & $40. var2 & $40.;
datalines;
1 It is a cat    This is a cat
2 a fox jump over a dog    Tom cat jump over a dog
;
run;
data want(drop=n i);
 set have;
 n=0;
 do i=1 to countw(var1);
  if upcase(scan(var1,i)) ne upcase(scan(var2,i)) then n+1;
 end;
 dif=divide(n,countw(var1));
run;

Xia Keshan

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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