date calculations

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

date calculations

Cynthia L Conley
Dear List,
I have a data set that has a variable with traditional date formats and gregorian calendar calculations (seconds) after merging data. Is there a way through the syntax that I can get all of the values under this same variable into the format of dd/mm/yyyy?
It appears that some of the data under this variable came in under numerical format, rather than date format. Any help you can provide is greatly appreciated.

Many Thanks,
Cindy

Cynthia L Conley, MSW, Ph.D.
University of Louisville
502-552-2999

Our deepest fear is not that we are inadequate.
Our deepest fear is that we are powerful beyond measure.

Marianne Williamson
Reply | Threaded
Open this post in threaded view
|

Re: date calculations

Richard Ristow
At 11:50 PM 7/4/2007, Cynthia L Conley wrote:

>Is there a way through the syntax that I can get all of the values
>under this same variable into the format of dd/mm/yyyy?

A point that sounds picky, but it matters: You probably do NOT want to
do that. You probably want to make the values true SPSS date values
(which have a special representation, but no intrinsic format), and
then assign a format so -they *display* as you desire. (As it happens,
there's no format that gives exactly what you're asking for. That is a
little awkward, but I still think making them SPSS date variables is
the right choice. You can assign them format ADATE10, which displays
them as 'mm/dd/yyyy'; or EDATE10, which displayst them as
'dd.mm.yyyy='. Or, choose another format you like - see Command Syntax
Reference section "Date and Time Formats".)

>I have a data set that has a variable with traditional date formats
>and gregorian calendar calculations (seconds) after merging data. It
>appears that some of the data under this variable came in under
>numerical format, rather than date format. Any help you can provide is
>greatly appreciated.

>Is there a way through the syntax that I can get all of the values...

It shouldn't be too bad, but we need to see exactly what you have. Is
it a string variable, or a numeric variable? "Traditional date formats"
sounds like it's a string. Then "gregorian calendar calculations
(seconds)" sounds like it might be an SPSS date value: "the number of
seconds since October 14, 1582", which can only be a numeric variable.

Anyway, SPSS date values are so different from most usual numeric
values that it's easy to distinguish them. But we'll need some example
data. If you print anything, print string variables with their native
format, and numeric variables with a nice wide format, like COMMA21.3.

Here's an example of the same dates in several display formats:

DATA LIST FREE / DATE (ADATE).
BEGIN DATA
01/01/1900
12/31/2000
07/04/2007
01/01/1990
END DATA.

FORMATS DATE (ADATE10).

COMPUTE DATE_VAL = DATE.
COMPUTE DATE_DAT = DATE.
FORMATS DATE_VAL (COMMA21.3).
FORMATS DATE_DAT (DATE11).
LIST.

List
|-----------------------------|---------------------------|
|Output Created               |05-JUL-2007 00:49:25       |
|-----------------------------|---------------------------|
       DATE              DATE_VAL    DATE_DAT

01/01/1900    10,010,390,400.000 01-JAN-1900
12/31/2000    13,197,600,000.000 31-DEC-2000
07/04/2007    13,402,886,400.000 04-JUL-2007
01/01/1990    12,850,531,200.000 01-JAN-1990

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