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-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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
  • 3342 views
  • 3 likes
  • 5 in conversation