Date: Tue, 26 Jun 2001 16:19:16 -0500
Reply-To: "Tverdek, Edward" <etverdek@SPSS.COM>
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: "Tverdek, Edward" <etverdek@SPSS.COM>
Subject: Re: syntax to make string into date
It's not really necessary to parse each date element into its own numeric
variable and recombine the three of them with a date aggregation function.
You can do the same thing by specifying ADATE as the target format in
computing a number based on the original string, as in
COMPUTE newdate=NUMBER(olddate,ADATE).
FORMATS newdate (ADATE).
EXE.
Only the new date variable of interest is created by this route. The same
concerns for two-digit years that Scott pointed out still apply. Run SHOW
EPOCH or check under Edit->Options->Data, and set the EPOCH accordingly.
Ed Tverdek
SPSS Technical Support
-----Original Message-----
From: Scott Czepiel [mailto:scott@sigmoidcurve.com]
Sent: Monday, June 25, 2001 5:37 PM
To: SPSSX-L@LISTSERV.UGA.EDU
Subject: Re: syntax to make string into date
Try this:
If your string variable is in the form "mm/dd/yyyy" and called sdat, then:
compute month = number(substr(sdat, 1, 2), F2.0).
compute day = number(substr(sdat, 4, 2), F2.0).
compute year = number(substr(sdat, 7, 4), F4.0).
formats datevar(date).
compute datevar = date.mdy(month, day, year).
execute.
If you're using "mm/dd/yy", SPSS will assume code this as 1901, so you'll
have to add 100 manually when computing year.
On Monday 25 June 2001 21:54, Dixon, Scott wrote:
> Hello,
>
> Does anyone know if there is a way to use FORMAT syntax to make a string
> variable such as "06/25/01" into a mm/dd/yy date variable?
>
> Thank you very much,
>
> Scott
|