| Date: | Thu, 2 Sep 2004 15:42:55 -0400 |
| Reply-To: | Mahbub Khandoker <Mahbub_Khandoker@camh.net> |
| Sender: | "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU> |
| From: | Mahbub Khandoker <Mahbub_Khandoker@camh.net> |
| Subject: | Re: Date again |
|
| Content-Type: | text/plain; charset="iso-8859-1" |
|---|
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
|