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?

 

 

9 REPLIES 9
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?

ChrisNZ
Tourmaline | Level 20

I still don't get how 2 swaps + 1 insert can work

 I meant 2 swaps + 1 replace, sorry about the confusion.

rudfaden
Lapis Lazuli | Level 10

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

 

rudfaden
Lapis Lazuli | Level 10
Sorry. All wrong.

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 9 replies
  • 2522 views
  • 3 likes
  • 5 in conversation