LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (December 2011)Back to main SPSSX-L pageJoin or leave SPSSX-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Thu, 1 Dec 2011 13:46:43 -0800
Reply-To:   David Marso <david.marso@gmail.com>
Sender:   "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From:   David Marso <david.marso@gmail.com>
Subject:   Re: SPSS cannot treat string variables as string variables?
In-Reply-To:   <CACdH1ViT+RFdGac7aAABpO_-TGpHG01q9M0xZj=n8AMVOD5New@mail.gmail.com>
Content-Type:   text/plain; charset=us-ascii

"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 &lt;huangpsych@&gt; 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 &lt;oliverr@.ibm&gt; 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@.ibm | Phone: 312.893.4922 | T/L: 206-4922 >>> >>> >>> >>> From: huang jialin &lt;huangpsych@&gt; >>> To: SPSSX-L@.uga >>> Date: 12/01/2011 10:50 AM >>> Subject: SPSS cannot treat string variables as string variables? >>> Sent by: "SPSSX(r) Discussion" &lt;SPSSX-L@.uga&gt; >>> ------------------------------ >>> >>> >>> >>> 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 >>> >> >> >

-- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/SPSS-cannot-treat-string-variables-as-string-variables-tp5039329p5040001.html Sent from the SPSSX Discussion mailing list archive at Nabble.com.

===================== To manage your subscription to SPSSX-L, send a message to LISTSERV@LISTSERV.UGA.EDU (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD


Back to: Top of message | Previous page | Main SPSSX-L page