DATA Step, Macro, Functions and more

Difficulty with the SPEDIS function

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 121
Accepted Solution

Difficulty with the SPEDIS function

Hi,

 

This is copied directly from Learning SAS by Example. My understanding is that when there is an exact match, the value should be 0, and that it increases the further away a match is. However, the results I am getting show a value of 137 for all the inputs except for Alfred, which is 166. Also, the lock says that the variable Friedman is unitiialized, whatever that means?

 

Any suggestions on why I am getting values of 137, and also what a variable that is unitialized means?

Thanks!

 

Here is the code:

------------------------

 

Data fuzzy ;

input Name $20. ;

Value = spedis(Name,‘Friedman’) ;

datalines ;

Friedman

Freedman

Xriedman

Freidman

Alfred

FRIEDMAN

;

 

Here are the results

-------------------------

 

Name       Value  Friedman

Friedman 137     .

Freedman 137    .

Xriedman 137     .

Freidman 137     .

Alfred 166           .

FRIEDMAN 137   .


Accepted Solutions
Solution
‎09-14-2017 04:38 PM
Super User
Posts: 6,626

Re: Difficulty with the SPEDIS function

Posted in reply to ManitobaMoose

The quotes you have around "Friedman" within the function are not true quotes ... they are some similar character.  Try deleting them, and re-typing the quotes, then re-run.

View solution in original post


All Replies
Solution
‎09-14-2017 04:38 PM
Super User
Posts: 6,626

Re: Difficulty with the SPEDIS function

Posted in reply to ManitobaMoose

The quotes you have around "Friedman" within the function are not true quotes ... they are some similar character.  Try deleting them, and re-typing the quotes, then re-run.

Super User
Posts: 13,293

Re: Difficulty with the SPEDIS function

Posted in reply to ManitobaMoose

The code you posted will not run.

This line

Value = spedis(Name,‘Friedman’) ;

has "smart quotes", the curly version instead of a simple '

 

After correcting that error when I run your code I get

Name Value
Friedman 0
Freedman 12
Xriedman 25
Freidman 6
Alfred 100
FRIEDMAN 87
So there may be something else going on.
Frequent Contributor
Posts: 121

Re: Difficulty with the SPEDIS function

Hi,

 

Thanks for looking at this. I did remove the quotes, but I am still getting the error with the same results. Below is the Text, and then the log:

 

CODE:

Data fuzzy ;

input Name $20. ;

Value = spedis(Name,Friedman) ;

datalines ;

Friedman

Freedman

Xriedman

Freidman

Alfred

FRIEDMAN

;

 

 

LOG:

62 Data fuzzy ;
63 input Name $20. ;
64 Value = spedis(Name,Friedman) ;
65 datalines ;
 
NOTE: Numeric values have been converted to character values at the places given by: (Line)Smiley SadColumn).
64:22
NOTE: Variable Friedman is uninitialized.
NOTE: The data set WORK.FUZZY has 6 observations and 3 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
Frequent Contributor
Posts: 121

Re: Difficulty with the SPEDIS function

Posted in reply to ManitobaMoose

OK. Now I got it to work. What are smart quotes vs simple quotes? Thanks!

Super User
Posts: 13,293

Re: Difficulty with the SPEDIS function

Posted in reply to ManitobaMoose

ManitobaMoose wrote:

OK. Now I got it to work. What are smart quotes vs simple quotes? Thanks!


Smart quotes are for word processing to make a start/end pair of smbols around the words look pretty like in typeset books.

The simple quote, in this case, is the programming language text identifier a value between ' '  or "  " is treated as text value

(except for the things like date and name literals which have an ending character pair like 'd 'dt "n and such).

 

Programming languages are build with limits, spell things right or get an error, use the correct symbol or get an error, end the statement correctly or get an error....

 

Follow the syntax rules to get the desired results.

Super User
Posts: 23,237

Re: Difficulty with the SPEDIS function

Posted in reply to ManitobaMoose

Use the code from the provided files or type it out. You're likely getting these errors by copying the code from a PDF file or EPUB file I assume...assuming a legal version. I've seen illegal versions in Doc files but I'm assuming you're using a legal version.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 247 views
  • 0 likes
  • 4 in conversation