|
Matthew,
I must respectfully disagree with everything you have just said ;-)
data list / dt (sdate) tm (time).
begin data
2011-01-18 00:54:19.000
end data.
COMPUTE datetime=dt+tm.
FORMATS datetime (DATETIME).
list.
DT TM DATETIME
2011/01/18 0:54:01 18-JAN-2011 00:54:01
Number of cases read: 1 Number of cases listed: 1
BTW: If the data were formatted as follows
DD-MM-YYYY HH:MM:SS you could read it as a DATETIME variable.
data list / dttm (datetime) .
begin data
18-01-2011 00:54:19
end data.
list.
DTTM
.
18-JAN-2011 00:54:19
Number of cases read: 2 Number of cases listed: 2
Pirritano, Matthew-2 wrote:
>
> "Read the variable in as a string. Not sure if other folks here would
> agree but as far as I can tell best practice for reading in data is to
> read everything in initially as strings. "
> --
>> I can't see why you would believe this!
>> If it can be read as a numeric field then do so rather than the overhead
>> of converting.
>
> "You can always change a string to a number but you can't always change a
> number to a string. Make
> sense?"
>> You can NOT always change a string to a NUMBER. Only if the string has
>> the appropriate format!
>
> "Then you can extract info from the string variable. For example you
> could create an SPSS readable date variable. You can run the following
> (datevar is the new version of the variable, and datestr is the original
> string version of the variables):"
>
> numeric datevar(adate10).
>
> compute datevar =
> date.mdy(number(char.substr(ltrim(rtrim(datestr)),6,2),f2.0),
> number(char.substr(ltrim(rtrim(datestr)), 9,2), f2.0),
> number(char.substr(ltrim(rtrim(datestr)),1,4), f4.0)).
>
> exe.
>
> This will create a variable that looks like 01/18/2011. That's the
> American Date format.
>
> "Don't forget about the rule that you don't overwrite a variable, create
> a new revised version."
> I'm not sure I would call this a "rule" so much as a personal preference
> and some sort of security against code which doesn't work correctly.
>
>
> Matthew Pirritano, Ph.D.
> Research Analyst IV
> Medical Services Initiative (MSI)
> Orange County Health Care Agency
> (714) 568-5648
> -----Original Message-----
> From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU] On Behalf Of
> John Fiedler
> Sent: Friday, February 11, 2011 7:47 AM
> To: SPSSX-L@LISTSERV.UGA.EDU
> Subject: Reading Date & Time from CSV File
>
> I am trying to parse a CSV tile with a time and date variable that looks
> like this:
> 2011-01-18 00:54:19.000
> What format do I use in my GET DATA command to read this?
> Thanks in advance!
> JOHN
>
> John Fiedler
> JohnFiedler@oreon.net
> Oreon Inc.
> 195 Wilderness Way
> Boise ID 83716-3383
> www.oreon.net Please visit our evolving website!
> +1.208.344.3255 (v)
> +1.208.381.0944 (f)
> +1.208.344.9979 (h
> +1.208.863.3727 (m) No cellular service at or near place of business nor
> at
> home.
>
> =====================
> 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
>
> =====================
> 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
>
>
--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Reading-Date-Time-from-CSV-File-tp3381430p3381627.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
|