If the string contains only numbers, you can convert it to numeric and then
compare to some other numeric. To convert use the following syntax:
RECODE stringvar (CONVERT) INTO newvar.
De: SPSSX(r) Discussion [mailto:[hidden email]] En nombre de
Enviado el: Tuesday, July 18, 2006 12:29 PM
Para: [hidden email] Asunto: comparing string to numeric
I would like you to help me on how I could compare a string to numeric
and vice versa.
To expand a little on what Hector Maletta wrote, which is correct:
At 11:28 AM 7/18/2006, Samuel Solomon wrote:
>I would like you to help me on how I could compare a string to numeric
>and vice versa.
The broad question is, what does it mean for your string and your
numeric quantities to be the same?
Hector wrote for what's probably the case: your string variable
contains the character representation of a numeric quantity, and 'the
same' means that they represent the same numeric quantity. Unless you
have more specifications, it's the only possible case, because a
numeric quantity does not have a canonical string representation. That
is, a numeric quantity can be converted to a string with the STRING
function; but if the quantity is 3, then '3', '003', and '3.00' are all
possible string conversions, none more representative of the quantity 3
than are any of the others.
So, if you have anything else in mind, you should probably write again.
One caveat: if your string does NOT represent a valid numeric quantity,
then the value of Hectors "newvar" will be system-missing. If you
compare it to your numeric quantity, the comparison will return
'missing', not 'false', and the difference matters in some cases.
So, don't test
"stringvar EQ newvar";
"MISSING(newvar) OR stringvar EQ newvar".