Date: Thu, 2 Sep 2004 15:18:04 -0500
Reply-To: "Oliver, Richard" <richard@spss.com>
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: "Oliver, Richard" <richard@spss.com>
Subject: Re: Date again
Content-Type: text/plain; charset="iso-8859-1"
Unless I'm missing something, the data presented in the example fit one of the supported date formats: SDATE. To be more precise, in this case SDATE11; so you could either read the data as SDATE11 to begin with or simply convert the string to a date with:
COMPUTE datevar=NUMBER(stringdate, sdate11).
FORMATS datevar (sdate11).
You could, of course, substitute another date format in the FORMATS command.
-----Original Message-----
From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU]On Behalf Of
Mahbub Khandoker
Sent: Thursday, September 02, 2004 2:43 PM
To: SPSSX-L@LISTSERV.UGA.EDU
Subject: Re: Date again
Thanks Richard, it's work fine.
-----Original Message-----
From: Richard Ristow [mailto:wrristow@mindspring.com]
Sent: September 2, 2004 3:35 PM
To: Mahbub Khandoker; SPSSX-L@LISTSERV.UGA.EDU
Subject: Re: Date again
At 02:06 PM 9/2/2004, Mahbub Khandoker wrote:
>I would like to convert the string date to normal date format.
>The dates (string) are now as follows,
>2004 Jan,11
>2003 Oct,18
>2004 Jun,10
>2003 Aug,15
>2004 May,03
Many date input problems in SPSS require some string manipulation and
the NUMBER function. Fortunately, that's usually all they take. Here's
one solution for this format. Tested code; this is SPSS draft output:
NEW FILE.
DATA LIST FIXED /CHAR_DT 01-11 (A).
Data List will read 1 records from the command file
Variable Rec Start End Format
CHAR_DT 1 1 11 A11
BEGIN DATA.
2004 Jan,11
2003 Oct,18
2004 Jun,10
2003 Aug,15
2004 May,03
END DATA.
/*-- LIST /*-*/.
STRING INTNL_DT (A11).
COMPUTE INTNL_DT = CONCAT(SUBSTR(CHAR_DT,10,02),'-', /* Day */
SUBSTR(CHAR_DT,06,03),'-', /* Month */
SUBSTR(CHAR_DT,01,04)) /* Year */.
/*-- LIST /*-*/.
- NUMERIC SPSS_DT (DATE11).
- VARIABLE WIDTH SPSS_DT (11).
- VARIABLE ALIGNMENT SPSS_DT (CENTER).
COMPUTE SPSS_DT = NUMBER(INTNL_DT,DATE11).
/**/ LIST /*-*/.
List
CHAR_DT INTNL_DT SPSS_DT
2004 Jan,11 11-Jan-2004 11-JAN-2004
2003 Oct,18 18-Oct-2003 18-OCT-2003
2004 Jun,10 10-Jun-2004 10-JUN-2004
2003 Aug,15 15-Aug-2003 15-AUG-2003
2004 May,03 03-May-2004 03-MAY-2004
Number of cases read: 5 Number of cases listed: 5