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 :
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?
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.
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?
SAS does not usually provide source code for its software as it is proprietary.
@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.
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.
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?
I still don't get how 2 swaps + 1 insert can work
I meant 2 swaps + 1 replace, sorry about the confusion.
if you swap f and u uzfiy you done and you get 200/5=40
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.
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.
Ready to level-up your skills? Choose your own adventure.