BookmarkSubscribeRSS Feed
sirivally
Calcite | Level 5

Hi,

I'm new to SAS. I'm trying to understand the behavior of SPEDIS function.

I ran below SAS code.

 

 

data new;
a = spedis('uzfiy', 'fuziy');
run;

According to my understanding from SAS documentation :

sirivally_1-1719850736853.png

Here, three operations are done

Query | Keyword 

  uzfiy      fuziy   

    Operation            |    Cost     

u - f   =>   firstrep          200

z - u  =>   replace         100

f - z   =>   replace         100

so, the result should be total cost / length of query =>   (200 + 100 + 100)/ 5 = 80.

But the actual result is 40.

can you please give me the actual operations done in this case ? And is there a way to get the source code of SPEDIS function?

 

 

8 REPLIES 8
ChrisNZ
Tourmaline | Level 20

The function tries for operations with the lowest score.

Consider:

data new;
  a = spedis('ABC', 'XAX');  
run;

This has a cost of 300 (and a distance of 100):

Swap A to first position: cost=100

Replace the other 2 letters: cost =2x100

 

Replacing everything would cost 200+100+100=400.

 

Similarly in your case, there are swaps rather than replacements used in the process.

Letters u and z can be put in the correct position with a swap, and f has to be inserted. Cost = 2x50+100 = 200, for a distance of 200/5 = 40.

 

sirivally
Calcite | Level 5

Thank you for your response.

Just want to make sure if it is 4 swaps or 2 swaps + 1 insertion in my case  ? 

If 4 swaps:

uzfiy - zufiy    -    50 

zufiy - zfuiy    -    50

zfuiy - fzuiy    -    50 

fzuiy - fuziy    -    50

                           =  200

SPEDIS - 200/5 = 40 

And is there a way to get the source code of SPEDIS function?

SASKiwi
PROC Star

SAS does not usually provide source code for its software as it is proprietary.

Kurt_Bremser
Super User

@sirivally wrote:

 

And is there a way to get the source code of SPEDIS function?


You have to ask SAS themselves for this, but I doubt they will provide it. SAS itself is not open source.

And it would only be helpful if you're good with C.

ChrisNZ
Tourmaline | Level 20

Just want to make sure if it is 4 swaps or 2 swaps + 1 insertion in my case  ? 

You swap from the start string, not from another combination. Otherwise you could just move a letter along till the end.

 

Kurt_Bremser
Super User

I still don't get how 2 swaps + 1 insert can work. After the swaps, you'd still have 5 characters, and the insert would result in 6 characters overall.

Could you please elaborate how the exact sequence 2 swaps + 1 insert works with the original text of the OP?

rudfaden
Pyrite | Level 9

if you swap f and u uzfiy you done and you get 200/5=40

 

rudfaden
Pyrite | Level 9
Sorry. All wrong.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 8 replies
  • 566 views
  • 3 likes
  • 5 in conversation