Re: string to number??

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: string to number??

Art Kendall-2
There is example syntax below the sig block.

Save all your current work, then open a new instance of SPSS. Make sure
that you put warnings, etc. into the output file. <edit> <options>
<viewer>. Cut-and-paste then run the syntax.
Please restate your question in more detail. What results you are
getting? how do they differ from what you want?
Are you getting any error messages?
Perhaps post a small data set with variables "have" and "want",



Art

Social Research Consultants





data list list/mystring (a8).
begin data
1.23456
12.3456
123.456
1234.56
12345.6
123456
.123456
.0123456
end data.
compute mynumber = number(mystring, f16.7).
formats mynumber (f16.7).
list.



Samuel Solomon wrote:

>
> Hi,
>
>
>
> How are you? I want to ask you simple question. How can I change a
> predefined string variable to the same numeric variable? I tried
> *number(argu,format)* function but it didn't serve me write. I am
> using spss11.0.
>
>
>
> Thanks,
>
>
>
> samuel
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: string to number??

Art Kendall-2
The variable "month" is a string.  One should rarely overwrite input
data. Also you cannot change the type of a variable via transformations.
try something like this.

numeric num_month (f2).
compute num_month = number(month,f2.0).

Art Kendall
Social Research Consultants

Samuel Solomon wrote:

>
> Your syntax works but that is not what I want. My variable is 'month'
> which is a string. I want the same variable but with a different
> format, which is numeric. I tried, compute month =number(month,F2.0)
> but it pops up the error below.
>
>
>
>
>
> >Error # 4309 in column 256.  Text: (End of Command)
>
> >Invalid combination of data types in an assignment.  Character strings may
>
> >only be assigned to string variables.  Numeric and logical quantities may
>
> >only be assigned to numeric variables.  Consider using the STRING or
> NUMBER
>
> >function.
>
> >This command not executed.
>
>
>
>
>
>
>
>
>
> ------------------------------------------------------------------------
>
> *From:* Art Kendall [mailto:[hidden email]]
> *Sent:* Tuesday, April 10, 2007 8:38 PM
> *To:* Samuel Solomon; SPSSX-L post
> *Subject:* Re: string to number??
>
>
>
> There is example syntax below the sig block.
>
> Save all your current work, then open a new instance of SPSS. Make
> sure that you put warnings, etc. into the output file. <edit>
> <options> <viewer>. Cut-and-paste then run the syntax.
> Please restate your question in more detail. What results you are
> getting? how do they differ from what you want?
> Are you getting any error messages?
> Perhaps post a small data set with variables "have" and "want",
>
>
>
> Art
>
> Social Research Consultants
>
>
>
>
>
> data list list/mystring (a8).
> begin data
> 1.23456
> 12.3456
> 123.456
> 1234.56
> 12345.6
> 123456
> .123456
> .0123456
> end data.
> compute mynumber = number(mystring, f16.7).
> formats mynumber (f16.7).
> list.
>
>
>
> Samuel Solomon wrote:
>
> Hi,
>
>
>
> How are you? I want to ask you simple question. How can I change a
> predefined string variable to the same numeric variable? I tried
> *number(argu,format)* function but it didn't serve me write. I am
> using spss11.0.
>
>
>
> Thanks,
>
>
>
> samuel
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>