Date: Tue, 16 Jul 1996 10:26:24 -0500
Reply-To: Jonathan Fry <jon@SPSS.COM>
Sender: "SPSSX(r) Discussion" <SPSSX-L@UGA.CC.UGA.EDU>
From: Jonathan Fry <jon@SPSS.COM>
Organization: SPSS Inc.
Subject: Re: Date Variable
SheridanY wrote:
>
> I have a date/time variable which is numeric and appears as 9607161133. I
> would like to take this and study date differences between cases. How can
> I convert this to date string that allows for calculation. I tried using
> compute-number(substr(string,f4)1,4)) so I could get the left four digits
> and it would not run.
> Thks.
> SY
--
You can get the first four digits as a number using
NUMBER(SUBSTR(STRING,1,4),"F4"), but the number you get might not be
all that useful for computation.
Converting the string to an SPSS date-time value will allow you to use
all of SPSS's built-in functions and formats for date and time data.
Time intervals are simply differences between such values.
I can think of two basic strategies for interpreting the string you
have: make a string with enough punctuation to satisfy the SPSS
date-time format conversion code, or pull out the parts with
arithmetic manipulation and use the date-time aggregation functions to
make a date-time variable. Here's an untested stab at the second
approach.
COMPUTE #DN = NUMBER(STRING,"F12") /* Turn the whole thing to a number
COMPUTE #YR = TRUNC(#DN/1E10).
COMPUTE #MO = MOD(TRUNC(#DN/1E8), 100).
COMPUTE #DA = MOD(TRUNC(#DN/1E6), 100).
COMPUTE #HR = MOD(TRUNC(#DN/1E4), 100).
COMPUTE #MI = MOD(TRUNC(#DN/100), 100).
COMPUTE #SE = MOD(#DN, 100).
COMPUTE DATE = DATE.DMY(#DA,#MO,#YR) + TIME.HMS(#HR,#MI,#SE).
If you want to study date differences (as opposed to time
differences), leave out TIME.HMS and its arguments.
--------------------
Jonathan Fry
SPSS Inc.
jon@spss.com
|