BookmarkSubscribeRSS Feed
shubha1babu
Calcite | Level 5

Hello All,

 

I have two variable var1 var2.

In var1 character is like "marutivx" and In var2 character is like "marutivx(0)". I need to calculate the similarities/differences by percentage.

Please help on little urgent basis.

 

Thanks,

Shubho

6 REPLIES 6
tomrvincent
Rhodochrosite | Level 12

This will help you:  http://support.sas.com/kb/48/582.html

 

Ksharp
Super User

That is a tough task. How you define similarities/differences ?

Anyway, COMPARE() might give you a little help.

 

data _null_;
var1="marutivx";var2="marutivx(0)";
diff=compare(var1,var2,'i');
put var1= var2= diff=;
run;
shubha1babu
Calcite | Level 5

Let me frame it once again.

I have 1000 obs. and two variables var1 and var2.I want to create 3rd variable which will show the similarities/differences between two strings by percentage wise.

ex.

var1          var2

maruti      marutix

vxez        vexz12

LX CNG  

               JHXD GX

and so on......

tomrvincent
Rhodochrosite | Level 12

That's what my previous post covers...the complev function.

shubha1babu
Calcite | Level 5

Great!! Thanks a lot Tom.It worked.

 

But I need little more help.Need to compare two strings by first 5 alphabets.

e.g     var1               var 2                 match_parentage

         marutix            marutisyz         100

 

Thanks.

 

ballardw
Super User

@shubha1babu wrote:

Great!! Thanks a lot Tom.It worked.

 

But I need little more help.Need to compare two strings by first 5 alphabets.

e.g     var1               var 2                 match_parentage

         marutix            marutisyz         100

 

Thanks.

 


Use the SUBSTR function to select the first 5 characters from each variable.

 

result = complev(substr(var1,1,5), substr(var2,1,5));

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 6 replies
  • 2216 views
  • 0 likes
  • 4 in conversation