SPSS cannot treat string variables as string variables?

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

SPSS cannot treat string variables as string variables?

huang jialin
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 
Reply | Threaded
Open this post in threaded view
|

Re: SPSS cannot treat string variables as string variables?

David Marso
Administrator
One must *DECLARE* string variables prior to use in transformation expressions!
STRING timedate (A11).

huang jialin wrote
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
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: SPSS cannot treat string variables as string variables?

Maguin, Eugene
In reply to this post by huang jialin

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:[hidden email]] On Behalf Of huang jialin
Sent: Thursday, December 01, 2011 11:48 AM
To: [hidden email]
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 

Reply | Threaded
Open this post in threaded view
|

Re: SPSS cannot treat string variables as string variables?

Rick Oliver-3
In reply to this post by huang jialin
You have to declare the new string variable first:

string timedate (a11).

But there are relatively simple ways to convert the original string to a real date.

Rick Oliver
Senior Information Developer
Business Analytics (SPSS)
E-mail: [hidden email] | Phone: 312.893.4922 | T/L: 206-4922




From:        huang jialin <[hidden email]>
To:        [hidden email]
Date:        12/01/2011 10:50 AM
Subject:        SPSS cannot treat string variables as string variables?
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




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 
Reply | Threaded
Open this post in threaded view
|

Re: SPSS cannot treat string variables as string variables?

huang jialin
Hi,

Thanks all for your quick responses. The Declare line works. 

To Gene, I do want the date reformatted. Thanks for the tips.

Thank you again.

Sincerely,
Jialin 


On Thu, Dec 1, 2011 at 11:15 AM, Rick Oliver <[hidden email]> wrote:
You have to declare the new string variable first:

string timedate (a11).

But there are relatively simple ways to convert the original string to a real date.

Rick Oliver
Senior Information Developer
Business Analytics (SPSS)
E-mail: [hidden email] | Phone: <a href="tel:312.893.4922" value="+13128934922" target="_blank">312.893.4922 | T/L: 206-4922




From:        huang jialin <[hidden email]>
To:        [hidden email]
Date:        12/01/2011 10:50 AM
Subject:        SPSS cannot treat string variables as string variables?
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




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 

Reply | Threaded
Open this post in threaded view
|

Re: SPSS cannot treat string variables as string variables?

huang jialin
Hi,

The same variable is as following. But I want to calculate the different between time. I have difficult transforming time format into military time.

Jun 22 2010  6:23AM
Apr 11 2011  3:16PM
Nov  1 2010 10:52PM
Aug 11 2011 12:05PM

I tried the CTIME.MINUTES () function, like compute time_diff=CTIME.MINUTES(SUBSTR(var0001,12,7)-SUBSTR(var0002,12,7)). 

How can I fix the problem of time difference?

Thanks.

Sincerely,
Jialin 
 

On Thu, Dec 1, 2011 at 12:00 PM, huang jialin <[hidden email]> wrote:
Hi,

Thanks all for your quick responses. The Declare line works. 

To Gene, I do want the date reformatted. Thanks for the tips.

Thank you again.

Sincerely,
Jialin 



On Thu, Dec 1, 2011 at 11:15 AM, Rick Oliver <[hidden email]> wrote:
You have to declare the new string variable first:

string timedate (a11).

But there are relatively simple ways to convert the original string to a real date.

Rick Oliver
Senior Information Developer
Business Analytics (SPSS)
E-mail: [hidden email] | Phone: <a href="tel:312.893.4922" value="+13128934922" target="_blank">312.893.4922 | T/L: 206-4922




From:        huang jialin <[hidden email]>
To:        [hidden email]
Date:        12/01/2011 10:50 AM
Subject:        SPSS cannot treat string variables as string variables?
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




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 


Reply | Threaded
Open this post in threaded view
|

Re: SPSS cannot treat string variables as string variables?

David Marso
Administrator
"I have difficult transforming time format into military time.".....

DATA LIST / strDate (A19).
BEGIN DATA
Jun 22 2010  6:23AM
Apr 11 2011  3:16PM
Nov  1 2010 10:52PM
Aug 11 2011 12:05PM
END DATA.
COMPUTE DatePart=NUMBER(CONCAT(
                           SUBSTR(strDate,5,2),"-",
                           SUBSTR(strDate,1,3),"-",
                           SUBSTR(strDate,8,4)),DATE11).
COMPUTE TIMEPart=NUMBER(SUBSTR(strDate,13,5),TIME).
IF ( SUBSTR(strDate,18,2)="PM" AND XDATE.HOUR(TimePart) < 12 ) TimePart = TimePart+12*60*60.
COMPUTE DateTime=DatePart+TimePart.
FORMATS DATEPart (DATE11).
FORMATS TimePart (Time5).
FORMATS DateTime (DateTime).

LIST.


STRDATE                DATEPART TIMEPART             DATETIME
Jun 22 2010  6:23AM 22-JUN-2010    6:23  22-JUN-2010 06:23:00
Apr 11 2011  3:16PM 11-APR-2011   15:16  11-APR-2011 15:16:00
Nov  1 2010 10:52PM 01-NOV-2010   22:52  01-NOV-2010 22:52:00
Aug 11 2011 12:05PM 11-AUG-2011   12:05  11-AUG-2011 12:05:00


Number of cases read:  4    Number of cases listed:  4

-----

huang jialin wrote
Hi,

The same variable is as following. But I want to calculate the different
between time. I have difficult transforming time format into military time.

Jun 22 2010  6:23AM
Apr 11 2011  3:16PM
Nov  1 2010 10:52PM
Aug 11 2011 12:05PM

I tried the CTIME.MINUTES () function, like compute time_diff=
CTIME.MINUTES(SUBSTR(var0001,12,7)-SUBSTR(var0002,12,7)).

How can I fix the problem of time difference?

Thanks.

Sincerely,
Jialin


On Thu, Dec 1, 2011 at 12:00 PM, huang jialin <[hidden email]> wrote:

> Hi,
>
> Thanks all for your quick responses. The Declare line works.
>
> To Gene, I do want the date reformatted. Thanks for the tips.
>
> Thank you again.
>
> Sincerely,
> Jialin
>
>
>
> On Thu, Dec 1, 2011 at 11:15 AM, Rick Oliver <[hidden email]> wrote:
>
>> You have to declare the new string variable first:
>>
>> string timedate (a11).
>>
>> But there are relatively simple ways to convert the original string to a
>> real date.
>>
>> Rick Oliver
>> Senior Information Developer
>> Business Analytics (SPSS)
>> E-mail: [hidden email] | Phone: 312.893.4922 | T/L: 206-4922
>>
>>
>>
>> From:        huang jialin <[hidden email]>
>> To:        [hidden email]
>> Date:        12/01/2011 10:50 AM
>> Subject:        SPSS cannot treat string variables as string variables?
>> Sent by:        "SPSSX(r) Discussion" <[hidden email]>
>> ------------------------------
>>
>>
>>
>> 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
>>
>
>
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: SPSS cannot treat string variables as string variables?

Rick Oliver-3
In reply to this post by huang jialin
The simple answer is that the CTIME functions work on time variables (or values expressed as a number of seconds), not strings.

Rick Oliver
Senior Information Developer
Business Analytics (SPSS)
E-mail: [hidden email] | Phone: 312.893.4922 | T/L: 206-4922




From:        huang jialin <[hidden email]>
To:        [hidden email]
Date:        12/01/2011 02:51 PM
Subject:        Re: SPSS cannot treat string variables as string variables?
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




Hi,

The same variable is as following. But I want to calculate the different between time. I have difficult transforming time format into military time.

Jun 22 2010  6:23AM
Apr 11 2011  3:16PM
Nov  1 2010 10:52PM
Aug 11 2011 12:05PM

I tried the CTIME.MINUTES () function, like compute time_diff=CTIME.MINUTES(SUBSTR(var0001,12,7)-SUBSTR(var0002,12,7)). 

How can I fix the problem of time difference?

Thanks.

Sincerely,
Jialin 
 

On Thu, Dec 1, 2011 at 12:00 PM, huang jialin <huangpsych@...> wrote:
Hi,

Thanks all for your quick responses. The Declare line works. 

To Gene, I do want the date reformatted. Thanks for the tips.

Thank you again.

Sincerely,
Jialin 



On Thu, Dec 1, 2011 at 11:15 AM, Rick Oliver <oliverr@...> wrote:
You have to declare the new string variable first:

string timedate (a11).


But there are relatively simple ways to convert the original string to a real date.


Rick Oliver
Senior Information Developer
Business Analytics (SPSS)
E-mail:
oliverr@... | Phone: <a href=tel:312.893.4922 target=_blank>312.893.4922 | T/L: 206-4922



From:        
huang jialin <huangpsych@...>
To:        
[hidden email]
Date:        
12/01/2011 10:50 AM
Subject:        SPSS cannot treat string variables as string variables?
Sent by:        "SPSSX(r) Discussion" <[hidden email]>





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