Date: Thu, 1 Dec 2011 12:12:37 -0500
Reply-To: Gene Maguin <emaguin@buffalo.edu>
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: Gene Maguin <emaguin@buffalo.edu>
Subject: Re: SPSS cannot treat string variables as string variables?
In-Reply-To: <CACdH1Vgzv5uCDh-z=kHw+Y6oU2wRJ49JEZYOs3=Cqb7d6Mju4Q@mail.gmail.com>
Content-Type: multipart/alternative;
The immediate answer is to declare timedate as A11, because var00001 is string and you are extracting a substring (as David said). The result, therefore, will be a string. But, I’d bet that’s not where you want to wind up. That is, you want timedate to be a numeric variable with a timedate format so that you can do arithmetic with it. That requires more work.
This is untested.
Compute Timedate=number(concat(substr(var00001,5,2),’-‘,substr(var00001,1,3),’-‘,substr(var00001,8,4)),date11).
Gene Maguin
From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU] On Behalf Of huang jialin
Sent: Thursday, December 01, 2011 11:48 AM
To: SPSSX-L@LISTSERV.UGA.EDU
Subject: SPSS cannot treat string variables as string variables?
Hi,
I imported data from SQL sever by ODBC. There is a string variable, formatted as following:
Jun 22 2010 6:23AM
Apr 11 2011 3:16PM
Nov 1 2010 10:52PM
Aug 11 2011 12:05PM
I tried to pull out the date only, by using substr() function in SPSS. Thus, my syntax is as below:
COMPUTE timedate=substr(var00001, 1, 11).
EXECUTE.
But I kept on having warning like this:
>Error # 4309 in column 1024. 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.
>Execution of this command stops.
However, in the variable view, it is a string variable. How can I solve this problem?
Thank you very much.
Sincerely,
Jialin
[text/html]
|