1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
*(Q) My ASCII file contains date stamp fields of the 
	format '01/01/89 05:16:25 AM.000000000'
 How can I read that information into a date and time variable. 

*(A) Posted to SPSSX-L list on 2003/04/08 by Raynald Levesque.


DATA LIST LIST /id siteid (2F8) name (A10) str1(A30).
BEGIN DATA
1, 1, 'Name 1', '01/01/89 05:16:25 AM.000000000' 
2, 152, 'Name 2', '01/01/95 10:18:25 PM.000000000' 
3, 17, 'Name 3', '01/01/02 10:18:25 AM.000000000' 
END DATA.


COMPUTE #space=INDEX(str1," ").
COMPUTE date1=NUMBER(SUBSTR(str1,1,#space-1),ADATE8).
COMPUTE #ampm=INDEX(str1,"M").
COMPUTE time1=NUMBER(SUBSTR(str1,#space,#ampm-2),TIME10).
FORMATS date1(ADATE8) time1(TIME10).
IF SUBSTR(str1,#ampm-1,2)="PM" time1= time1 + 12*60*60.
LIST.