1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
SPSS AnswerNet: Result 

Solution ID:	 	100000632	
Product:	 	SPSS Base 	
Title:
Using date variables in TABLES 
Description:
Q. 
I have a date variable where I'd like to get the mean and standard 
deviation in days. When I run the table, I get the mean, but the 
standard deviation isn't coming out correctly. I get either all 
asterisks, or some really high number. How can I get the standard 
deviation out of the date variable? 
A. 
The following shows how to get a table that has the mean date and 
standard deviation in days from the mean date. 
* Here is a sample data file. Suppose we want to get 
* the mean date and standard deviation in days of the 
* DT variable by the VARA variable. 
DATA LIST fixed / dt 1-8 (adate) vara 10. 
BEGIN DATA 
06/11/50 1 
11/17/53 1 
01/19/56 2 
08/26/59 2 
END DATA. 
* The first thing we do is to use AGGREGATE to compute 
* a variable that represents the standard deviation of 
* the DT variable. We can then incorporate that value 
* back to our original data file. 

AGGREGATE outfile=temp.sav / break=vara 
/sddt=sd(dt). 
MATCH FILES file=* / table=temp.sav / by vara. 

* Since the new variable (SDDT) is stored as 
* of seconds, we can use a COMPUTE command to translate 
* this value into days by using the CTIME.DAYS function. 

COMPUTE sddt=trunc(ctime.days(sddt)). 
EXECUTE. 
FORMATS sddt (f5.0). 
* Some cosmetic work here. 

VARIABLE LABELS dt 'Mean Date' 
sddt 'Standard Deviation in Days' . 
* Now we will compute the table. We will use DT and 
* SDDT. Although SDDT represents a standard deviation, 
* we will use the MEAN statistics to represent it. 
* This is because the standard deviation is already 
* computed in the dataset, and we just want to display 
* the value in the dataset. We can use the MEAN statistic 
* to do that. 
TABLES observation=dt sddt 
/table=dt+sddt by vara 
/statistics mean(dt'') mean(sddt'').