Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Add leading zero in string/date field

336 views
Skip to first unread message

astrogirl

unread,
Jun 19, 2009, 11:08:46 AM6/19/09
to
I have a variable in string format mm/dd/yyyy that I want to change to
dd-mmm-yyyy. I can do this through the date/time wizard in SPSS 16 but
there is a problem. The days that are single digits (ex. 12/3/2008)
are not recognized by the wizard and they are being left blank in the
new date field. If they have a double digit day, then they convert
correctly.

So, is there a way to insert a 0 after the first slash mark for just
the records which have a single digit date?

Thanks for any help anyone can give me.

Angie

Art Kendall

unread,
Jun 19, 2009, 11:37:32 AM6/19/09
to
In version 17 and IIRC for years, using European date format puts the
leading zeros in the display.
Try this:

new file.
data list list /id (f3) datestring (A10).
begin data.
1 1/1/2009
2 01/01/2009
3 01/21/2009
4 1/21/2009
end data.
numeric mydate(edate10).
compute mydate = number(datestring,adate10).
LIST .

Art Kendall
Social Research Conultants

astrogirl

unread,
Jun 19, 2009, 12:08:53 PM6/19/09
to
That worked!! Thank you very much Art.

Bruce Weaver

unread,
Jun 19, 2009, 1:06:50 PM6/19/09
to

Could you post the syntax you generated with the Date & Time Wizard
(DTW)? I'm curious, because the DTW generated code for me (using
v16.02) that worked on Art's little sample file.

new file.
data list list /id (f3) datestring (A10).
begin data.
1 1/1/2009
2 01/01/2009
3 01/21/2009
4 1/21/2009
end data.

* Date and Time Wizard: mydate.
COMPUTE mydate=number(datestring, ADATE10).
VARIABLE LABEL mydate "".
VARIABLE LEVEL mydate (SCALE).
FORMATS mydate (ADATE10).
VARIABLE WIDTH mydate(10).
list.

OUTPUT:

id datestring mydate

1 1/1/2009 01/01/2009
2 01/01/2009 01/01/2009
3 01/21/2009 01/21/2009
4 1/21/2009 01/21/2009

Number of cases read: 4 Number of cases listed: 4

--
Bruce Weaver
bwe...@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/
"When all else fails, RTFM."

0 new messages